lua-users home
lua-l archive

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


Tuesday, September 5, 2006, 2:29:39 PM, Edgar Toernig wrote:

> Module private registries are easy:

>     #define MY_REGISTRY lua_upvalueindex(1)

> and then make sure that you put the registry table into the first
> upvalue of each function of your module.

Yes, I see. That would be a bit faster and safer than using the global
registry, at the cost of an extra slot in each of the closures.

But wait! Lua 5.1's LUA_ENVIRONINDEX can create a shared environment
among the C functions without adding any closure slots. This is not
too well documented (at least I couldn't find anything that made it
clear to me until I read the source code).

I finally found Mike Pall's example; it is instructive despite being
primarily concerned with userdata environments, "the example shows how
to use the new C function environment, too"
http://lua-users.org/lists/lua-l/2005-04/msg00213.html

I also now appreciate Luis Carvalho's suggestion in
http://lua-users.org/lists/lua-l/2006-08/msg00505.html
"For more examples of LUA_ENVIRONINDEX, check liolib.c."

Thanks!

e

-- 
Doug Currie
Londonderry, NH