【发布时间】:2021-08-24 17:03:45
【问题描述】:
如何在 lua 中自定义 ++、-=、+= 运算符?因为它缺少递增/递减运算符。
我正在尝试,这是我的代码:
local opTable = {}
debug.setmetatable(0, {
__call = function(a, op)
return opTable[op](a)
end
})
opTable["++", int + 1] -- The rest of the code works, this is the main line that's the problem.
local x = 2;
print(x++)
我也想知道怎么做+=和-=,或者可能怎么做/=或*=和%=。
【问题讨论】: