mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-29 16:43:17 +00:00
lua: make it easier to disable strict mode global variables
After this commit, the "strict mode" lua variable errors may be disabled with ilua.strict = false and reenabled with ilua.strict = true There will typically be no noticeable performance difference from previously to this commit. This is a bit simpler than the other methods described which include using pcall or resetting the metatable of _G.
This commit is contained in:
parent
567f135f1e
commit
748f872091
@ -21,7 +21,7 @@ local declared = {}
|
||||
|
||||
local jstack = {}
|
||||
|
||||
local ilua = {}
|
||||
local ilua = { strict = true }
|
||||
|
||||
function ilua.join(tbl,delim,limit,depth)
|
||||
if not limit then limit = pretty_print_limit end
|
||||
@ -127,7 +127,7 @@ function ilua.set_strict()
|
||||
end
|
||||
|
||||
mt.__index = function (t, n)
|
||||
if not declared[n] and what() ~= "C" then
|
||||
if not declared[n] and ilua.strict and what() ~= "C" then
|
||||
error("variable '"..n.."' must be assigned before being used", 2)
|
||||
end
|
||||
return rawget(t, n)
|
||||
|
Loading…
x
Reference in New Issue
Block a user