Fix console spaming by debug function on mod checking for global variable to exist.

This commit is contained in:
sapier 2014-11-23 15:24:37 +01:00
parent 0164483310
commit 0dcc4b251f

@ -11,7 +11,7 @@ end
local meta = {} local meta = {}
local declared = {} local declared = {}
local alreadywarned = {}
function meta:__newindex(name, value) function meta:__newindex(name, value)
local info = debug.getinfo(2, "Sl") local info = debug.getinfo(2, "Sl")
@ -36,9 +36,10 @@ end
function meta:__index(name) function meta:__index(name)
local info = debug.getinfo(2, "Sl") local info = debug.getinfo(2, "Sl")
if not declared[name] and info.what ~= "C" then if not declared[name] and info.what ~= "C" and not alreadywarned[name] then
warn(("Undeclared global variable %q accessed at %s:%s") warn(("Undeclared global variable %q accessed at %s:%s")
:format(name, info.short_src, info.currentline)) :format(name, info.short_src, info.currentline))
alreadywarned[name] = true
end end
return rawget(self, name) return rawget(self, name)
end end