lua-users home
lua-l archive

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

(Re)read the documentation, getglobal looks up stuff with string keys in _G / the global environment. newmetatable takes an arbitrary name for your new metatable that has nothing to do with fields in the global environment. You could name your metatable "asdf" and exactly the same thing would happen.

>> Have you checked what you're actually doing, on the Lua-level?
>>> luaL_newmetatable( L, "_G"));
>> local temp = {} ; debug.getregistry()._G = temp

So yes, at some point you'll have to push _G and actually set its metatable, and probably also point parts of your construction at it. (I don't get how it's supposed to work, do you make a new "shadow table" and reroute *all* nonexistent stuff over there, or do you want to mostly put stuff back into _G?)

I strongly suggest you make it work in Lua first and then translate to C.

-- nobody