Jump to content

Module:No globals

From Simple English Wikipedia, the free encyclopedia

This module causes an error if any nilglobalis read or if any global is written to, with the exception ofarg.To use, addrequire('Module:No globals')to the top of the module using it. Theargvariable is excluded because it is necessary for Scribunto'srequirefunction to work properly. (See the Scribunto source codehere.)

See also


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