// create new table
lua_newtable( L );
int Table = lua_gettop( L );
// add closure 1 with 2 upvalues
lua_pushstring( L, "Closure1" );
lua_pushinteger( L, 1 );
lua_pushinteger( L, 2 );
lua_pushcclosure( L, Function, 2 );
lua_settable( L, Table );
// add closure 2 with 1 upvalue
lua_pushstring( L, "Closure2" );
lua_pushinteger( L, 1 );
lua_pushcclosure( L, Function, 1 );
lua_settable( L, Table );
// set the name of the table
lua_setglobal( L, "Table1" );
The table should work like this:
[font="Courier New"]Table1.Closure1()
Table1.Closure2()[/font]
It always crashes at the lua_settable calls. I believe the reason for this is because the stack is supposed to be arranged with the key before the value, but doing that would mess up the closure.
Anyone know how to get around this?
Thanks.