Editing Module:No globals
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
local mt = getmetatable(_G) or {} | local mt = getmetatable(_G) or {} | ||
function mt.__index (t, k) | local oldIndex = mt.__index or function() return nil end | ||
if k ~= 'arg' then | mt.__index = function(t, k) | ||
if k ~= 'name' and k ~= 'arg' then | |||
error | error('Tried to read nil global ' .. tostring(k), 2) | ||
end | end | ||
return | return oldIndex(t, k) | ||
end | end | ||
local oldNewindex = mt.__newindex or rawset | |||
function mt.__newindex(t, k, v) | function mt.__newindex(t, k, v) | ||
if k ~= 'arg' then | if k ~= 'name' and k ~= 'arg' then | ||
error | error('Tried to write global ' .. tostring(k), 2) | ||
end | end | ||
oldNewindex(t, k, v) | |||
end | end | ||
setmetatable(_G, mt) | setmetatable(_G, mt) |