lua-users home
lua-l archive

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


I am revising some of my code which uses a light userdata stored in the registry to allow Lua functions coded in C to access a C++ object. This is a common issue which will come up in a number of different contexts such as multi-threading.

 

While the registry solution works fine, it occurs to me that it would be more efficient to store this frequently accessed pointer in the userdata supplied to lua_newstate. However, while this is passed back to the memory allocator function, there is no API to recover it from the lua_State. Examination of the lua sources enabled me to write such a function fairly trivially, but it occurs that this would be a useful addition to the API – say:

 

void *lua_getallocud(lua_State *L)

 

I know about the LUAI_EXTRASPACE feature to stash extra data in the state, but using this requires recompilation of the Lua code library whereas the above approach could be used as-is.