Module:No globals

From RimWorld Wiki
Revision as of 02:44, 6 July 2024 by Arcangelus (talk | contribs) (Older alternative of module strict.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

https://www.mediawiki.org/wiki/Module:No_globals/doc This is a deprecated module, and if anyone can import the module 'strict' this should be removed. In the meantime, this will allow certain templates to function.

General[edit]

This module is deprecated in most use cases, use strict library: require( "strict" )

Usage[edit]

Include this module at the top of your code. An error will be raised any time your code tries to read or write to a non-local (undeclared) variable.


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)