lua-users home
lua-l archive

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

On Nov 19, 2010, at 8:59 PM, Nick Gammon wrote:

> [...]
> So what is really the recommended way of storing some global data (eg. a pointer) for Lua to get back its C environment? An "upvalue with a shared table" is different from the registry is it not?
> Is there some reason you suggest using the upvalue rather than the LUA_REGISTRYINDEX table? Would it be faster?

An upvalue can be private to the function (when created with lua_pushcclosure), or to the functions in a module (when created with luaL_setfuncs). Being private makes them safe from accidental (or using sandbox techniques, malicious) modification or deletion by code outside your module. 

Whether using upvalues would be faster than refs in the registry depends on how much is in the registry, among other things. 

These are the same kind of trade-offs as local versus global variables.