blob: 6ee62a98f07accdb85d0eb4cd42ecddcc3f58218 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
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)
|