I have the following problem using the native Lua <-> C bridge in the Corona Simulator under OS X. I try to push a C closure onto the stack, everything works fine, but when I try to retrieve the indices of upvalues within the function, I get some crazy values and thus can not access the upvalues.
static int get_closure (lua_State *L)
{
lua_pushnumber(L, 0);
lua_pushcclosure(L, &closure, 1);
return 1;
}
static int closure (lua_State *L)
{
int index = lua_upvalueindex(1); // The index here is something like: -6001001
int upvalue = luaL_checkint(L, index); // ERROR: bad argument
<othe code which is never called>
}
The same code works well in Lua 5.1 and 5.2. Creation of closure and calling the closure function works well in Corona Simulator.