lua-users home
lua-l archive

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


Have you checked what you're actually doing, on the Lua-level?

> void GLOBAL_lock (lua_State *L) {
>  luaL_newmetatable( L, "_G"));
>  lua_pushvalue(L, -1); /* duplicate the metatable */
>  lua_setfield(L, -2, "__index");
>  lua_pushcfunction( L, lock_new_index);
>  lua_setfield( L, -2, "__newindex");
>  luaL_setmetatable( L, "_G");
> }

That's effectively a

local temp = {} ; debug.getregistry()._G = temp
temp.__index = temp
temp.__newindex = lock_new_index
debug.setmetatable( temp, debug.getregistry()._G )

…and then you're not saving temp anywhere where you can experiment with it from Lua. You probably wanted to push the global environment at some point?

-- nobody