Module:No globals: Difference between revisions
← Older edit
Newer edit →
Module:No globals (view source)
Revision as of 20:46, 23 April 2014
118 BYTES REMOVED
,  8 YEARS AGO
don't bother saving old __index or __newindex
local mt = getmetatable(_G) or {}
local oldIndex =function mt.__index or(t, function(k) return nil end
mt.__index = function(t, k)
if k ~= 'name' and k ~= 'arg' then
error('Tried to read nil global ' .. tostring(k), 2)
end
return oldIndex(t, k)nil
end
local oldNewindex = mt.__newindex or rawset
function mt.__newindex(t, k, v)
if k ~= 'name' and k ~= 'arg' then
error('Tried to write global ' .. tostring(k), 2)
end
oldNewindexrawset(t, k, v)
end
setmetatable(_G, mt)
Jackmcbarn
AUTOPATROLLERS
2,535
EDITS
Privacy policy
Terms of Use
Desktop
HomeRandom Nearby Log inDonateAbout Wikimedia CommonsDisclaimers