我已经反编译了一些lua代码,能够理解其中的大部分。
但是,我在代码中看到的这些UPVALUE0、UPVALUE1等关键字,据我所知,在任何地方都没有定义。
这里有一个例子:
local L0_0
L0_0 = module
L0_0((...), package.seeall)
function L0_0(A0_1)
if A0_1 - math.floor(A0_1) > 0 then
error("trying to use bitwise operation on non-integer!")
end
end
bit = {
bxor = function(A0_17, A1_18)
local L2_19, L3_20, L4_21, L5_22
L2_19 = _UPVALUE0_
L3_20 = A0_17
L2_19 = L2_19(L3_20)
L3_20 = _UPVALUE0_
L4_21 = A1_18
L3_20 = L3_20(L4_21)
L4_21 = _UPVALUE1_
L5_22 = L2_19
L4_21(L5_22, L3_20)
L4_21 = {}
L5_22 = math
L5_22 = L5_22.max
L5_22 = L5_22(table.getn(L2_19), table.getn(L3_20))
for _FORV_9_ = 1, L5_22 do
if L2_19[_FORV_9_] ~= L3_20[_FORV_9_] then
L4_21[_FORV_9_] = 1
else
L4_21[_FORV_9_] = 0
end
end
return _UPVALUE2_(L4_21)
end
}
它们是什么意思?
来源https://www.lua.org/pil/6.1.html:
。。既不是全局变量,也不是局部变量。我们称之为外部局部变量或上值。(术语"upvalue"是几乎没有误导性,因为它是一个变量,而不是一个值。然而这个术语的历史根源于卢阿,它比"外部"更短局部变量"。(
local i = 0
function inc()
i = i + 1
return i
end
函数inc
中的变量i
是upvalue,因为它不是此函数中的局部变量,也不是全局变量。