From 748f87209188324e45acdba2fbd0483d069cfab8 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Mon, 5 Jan 2015 14:58:09 -0500 Subject: [PATCH] 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. --- data/lua/ilua.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/lua/ilua.lua b/data/lua/ilua.lua index 63ca2f55486..50ebeadc82e 100644 --- a/data/lua/ilua.lua +++ b/data/lua/ilua.lua @@ -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)