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
1 changed files with 2 additions and 2 deletions
|
@ -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…
Add table
Reference in a new issue