Setting Global (_G)'s Metatable

I dont know if this is correct coding in Lua :stuck_out_tongue: but when you set the metatable of the Global Variable it completely crashes Codea :slight_smile:

Code:
local m_G = {
__index = function(self, key)
print("accessing: " … tostring(key))
end,
}

setmetatable(_G, m_G)

this works all right. You should probably call it in your setup function. If you do this outside of the setup function with this function, codea will not be able to find its setup function (because it looks it up in the _G table, and your __index function returns nil), which is probably why it crashes. Your __index function should probably return some value like rawget(self, key) in order to keep codea working.

Ya I guess that makes sense. I’ll try that.
Thanks :slight_smile: