I think function upvalues are faster in general. On the other hand registry also has the advantage that it works for all functions, not just a chosen few, and can scale to any number of needed C++ objects (plus, if speed is an issue, lua_rawget will be faster than lua_getfield). If the number of functions to be used is small, and the number of C++ objects is small, then function upvalues are likely better.
On May 21, 2008, at 10:50 AM, Ignacio Burgueño wrote: 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
Be seeing you
grrr waaa www.grahamwakefield.net
|