Module:No globals: Difference between revisions
m
7 revisions imported from wikipedia:Module:No_globals
(←Created page with 'local mt = getmetatable(_G) or {} local oldIndex = mt.__index or function() return nil end mt.__index = function(t, k) if k ~= 'name' and k ~= 'arg' then erro...') |
m (7 revisions imported from wikipedia:Module:No_globals) |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1:
local mt = getmetatable(_G) or {}
▲ if k ~= 'name' and k ~= 'arg' then
error('Tried to read nil global ' .. tostring(k), 2)
end
return
end
function mt.__newindex(t, k, v)
if
error('Tried to write global ' .. tostring(k), 2)
end
end
setmetatable(_G, mt)
|