是否可以区分来电
myFunc()
来自
myFunc(nil)
在函数 myFunc 中?
最佳答案
实际上,在 Lua 函数中区分 nil
值和无值是可能的,前提是它们需要使用 ...
运算符的可变数量的参数。但是,利用它既不是很容易也不合理。示例:
function myFunc(...)
if select('#', ...) == 0 then
print "Called without argument"
elseif select('#', ...) == 1 and select(1, ...) == nil then
print "Called with a nil argument"
end
end
关于function - 在lua中检测单个零参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12622912/