lua-users home
lua-l archive

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


I unfortunately am working on a controller without any display, so I
do not have any debugging access to Lua ... .

If I understand you correctly, you want to tell me that with
luaL_newmetatable( L, "_G") I do NOT connect to the global table _G,
but instead I would somehow create a temporary/local table?

On Thu, Oct 14, 2021 at 4:31 PM nobody <nobody+lua-list@afra-berlin.de> wrote:
>
> 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
>