pra*_*pin 8

实际上,可以nil在Lua函数中区分值和无值,前提是它们期望与...运算符有可变数量的参数.但是,利用它并​​不是非常容易也不合理.例:

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
Run Code Online (Sandbox Code Playgroud)