This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected.
This template may have no transclusions, because it is intended largely for debugging the use of globals.
This module finds nil global variable use and adds the to the Lua log along with where they were read/written. This module is different from require('strict') as you can see all nil global variables that are being read/written to rather than only getting an error for the first problematic global variable. The arg variable is excluded.
See also
require('strict') - Creates error message for first encountered nil global read/write
localmt=getmetatable(_G)or{}localfunctionprint(val)iftype(val)=="table"thenlocalprintout={}locali=1fork,vinpairs(val)dotable.insert(printout,("[%s] = %s"):format(tostring(k),tostring(v)))i=i+1ifi>5thentable.insert(printout,"...")breakendendprintout={table.concat(printout,", ")}table.insert(printout,1,"{")table.insert(printout,"}")returntable.concat(printout)elseiftype(val)=="string"thenreturn'"'..val..'"'elsereturntostring(val)endendmt.__newindex=function(self,key,value)ifkey~="arg"thenmw.log("Global variable "..print(key).." was set to "..print(value).." somewhere:",debug.traceback("",2))endreturnrawset(self,key,value)endmt.__index=function(self,key)ifkey~="arg"thenmw.log("Nil global variable "..print(key).." was read somewhere:",debug.traceback("",2))endreturnrawget(self,key)endsetmetatable(_G,mt)