Module:No globals

From Center for Integrated Circuits and Devices Research (CIDR)
Revision as of 20:43, 4 September 2022 by Louis Alarcon (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:No globals/doc

 1 local mt = getmetatable(_G) or {}
 2 function mt.__index (t, k)
 3 	if k ~= 'arg' then
 4 		error('Tried to read nil global ' .. tostring(k), 2)
 5 	end
 6 	return nil
 7 end
 8 function mt.__newindex(t, k, v)
 9 	if k ~= 'arg' then
10 		error('Tried to write global ' .. tostring(k), 2)
11 	end
12 	rawset(t, k, v)
13 end
14 setmetatable(_G, mt)