mirror of
https://github.com/luanti-org/luanti.git
synced 2026-04-17 08:37:33 +00:00
Minor refactor in strict.lua
This commit is contained in:
+14
-14
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user