mirror of
https://github.com/vxcontrol/lualibs-luajit.git
synced 2026-07-01 14:40:45 -04:00
fix for strict.lua over stripped bytecode
This commit is contained in:
+9
-9
@@ -5,6 +5,8 @@
|
||||
-- (even assigning nil will do) in a main chunk before being used
|
||||
-- anywhere or assigned to inside a function.
|
||||
--
|
||||
-- modified for better compatibility with LuaJIT, see:
|
||||
-- http://www.freelists.org/post/luajit/strictlua-with-stripped-bytecode
|
||||
|
||||
local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget
|
||||
|
||||
@@ -16,15 +18,10 @@ end
|
||||
|
||||
mt.__declared = {}
|
||||
|
||||
local function what ()
|
||||
local d = getinfo(3, "S")
|
||||
return d and d.what or "C"
|
||||
end
|
||||
|
||||
mt.__newindex = function (t, n, v)
|
||||
if not mt.__declared[n] then
|
||||
local w = what()
|
||||
if w ~= "main" and w ~= "C" then
|
||||
local info = getinfo(2, "S")
|
||||
if info and info.linedefined > 0 then
|
||||
error("assign to undeclared variable '"..n.."'", 2)
|
||||
end
|
||||
mt.__declared[n] = true
|
||||
@@ -33,8 +30,11 @@ mt.__newindex = function (t, n, v)
|
||||
end
|
||||
|
||||
mt.__index = function (t, n)
|
||||
if not mt.__declared[n] and what() ~= "C" then
|
||||
error("variable '"..n.."' is not declared", 2)
|
||||
if not mt.__declared[n] then
|
||||
local info = getinfo(2, "S")
|
||||
if info and info.linedefined > 0 then
|
||||
error("variable '"..n.."' is not declared", 2)
|
||||
end
|
||||
end
|
||||
return rawget(t, n)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user