Minor refactor in strict.lua

This commit is contained in:
sfan5
2026-04-13 00:56:10 +02:00
parent 0b6a482037
commit 68725763f1
+14 -14
View File
@@ -18,17 +18,17 @@ function meta:__newindex(name, value)
if declared[name] then
return
end
local info = debug_getinfo(2, "Sl")
if info ~= nil then
local desc = ("%s:%d"):format(info.short_src, info.currentline)
local warn_key = ("%s\0%d\0%s"):format(info.source, info.currentline, name)
if not warned[warn_key] and info.what ~= "main" and info.what ~= "C" then
core.log("warning", ("Assignment to undeclared global %q inside a function at %s.")
:format(name, desc))
warned[warn_key] = true
end
end
declared[name] = true
local info = debug_getinfo(2, "Sl")
if info == nil or info.what == "C" or info.what == "main" then
return
end
local warn_key = ("%s\0%d\0%s"):format(info.source, info.currentline, name)
if not warned[warn_key] then
warned[warn_key] = true
core.log("warning", ("Assignment to undeclared global %q inside a function at %s:%d")
:format(name, info.short_src, info.currentline))
end
end
@@ -37,14 +37,14 @@ function meta:__index(name)
return
end
local info = debug_getinfo(2, "Sl")
if info == nil then
if info == nil or info.what == "C" then
return
end
local warn_key = ("%s\0%d\0%s"):format(info.source, info.currentline, name)
if not warned[warn_key] and info.what ~= "C" then
core.log("warning", ("Undeclared global variable %q accessed at %s:%s")
:format(name, info.short_src, info.currentline))
if not warned[warn_key] then
warned[warn_key] = true
core.log("warning", ("Undeclared global variable %q accessed at %s:%d")
:format(name, info.short_src, info.currentline))
end
end