local gbl_mt = {} local decl = {} function gbl_mt:__index(k) if not decl[k] then error("unknown global: "..k, 2) end return rawget(self, k) end function gbl_mt:__newindex(k, v) if not decl[k] then error("unknown global: "..k, 2) end rawset(self, k, v) end function global(k, v) decl[k] = true rawset(_G, k, v) end setmetatable(_G, gbl_mt)