lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Ignacio Burgueño wrote:

EHm, if I understood right, you want to access MyThing objects only from C functions called by Lua. You can have it available as an upvalue of the function. You do that when registering the functions in Lua:

lua_pushlightuserdata(L, thing);
lua_pushcclosure(L, your_C_function, 1);
lua_setglobal(L, "yourFunctionName");



I forgot to tell how you access it later in your C function:

//////////////////////////////////////////////////////////////////////////
///
int your_C_function(lua_State* L) {
	MyThing* theThing = (MyThing*)lua_touserdata(L, lua_upvalueindex(1));

etc...


Also, Peter and Graham suggested using the registry. Which approach is faster? (i.e. less table lookups, etc)

Regards,
Ignacio