2020-11-19 20:40:36 +00:00
|
|
|
local strict = {}
|
|
|
|
strict.defined = {}
|
|
|
|
|
|
|
|
|
|
|
|
-- used to define a global variable
|
|
|
|
function global(t)
|
|
|
|
for k, v in pairs(t) do
|
|
|
|
strict.defined[k] = true
|
|
|
|
rawset(_G, k, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function strict.__newindex(t, k, v)
|
|
|
|
error("cannot set undefined variable: " .. k, 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function strict.__index(t, k)
|
2023-02-21 00:50:02 +00:00
|
|
|
if not strict.defined[k] and k ~= nil then
|
2020-11-19 20:40:36 +00:00
|
|
|
error("cannot get undefined variable: " .. k, 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
setmetatable(_G, strict)
|