Module:No globals

From Constructed Worlds Wiki
Jump to navigation Jump to search
Wikipedia logo This page uses material from the Wikipedia page Module:No globals, which is released under the Creative Commons Attribution-ShareAlike 3.0 Unported License (view authors).

local mt = getmetatable(_G) or {}
function mt.__index (t, k)
	if k ~= 'arg' then
		error('Tried to read nil global ' .. tostring(k), 2)
	end
	return nil
end
function mt.__newindex(t, k, v)
	if k ~= 'arg' then
		error('Tried to write global ' .. tostring(k), 2)
	end
	rawset(t, k, v)
end
setmetatable(_G, mt)