Lua unpack() messing arguments

前端 未结 1 692
没有蜡笔的小新
没有蜡笔的小新 2020-12-20 20:26

I have this test function which simply prints values passed to it

function test1(...)
  for k, v in ipairs(arg) do
    print(v)    
  end
end

function test2         


        
相关标签:
1条回答
  • 2020-12-20 20:47

    This behavior is not specific to unpack. The Lua Reference Manual says:

    "Both function calls and vararg expressions can result in multiple values. If a function call is used as a statement (see §3.3.6), then its return list is adjusted to zero elements, thus discarding all returned values. If an expression is used as the last (or the only) element of a list of expressions, then no adjustment is made (unless the expression is enclosed in parentheses). In all other contexts, Lua adjusts the result list to one element, either discarding all values except the first one or adding a single nil if there are no values."

    (my emphasis)

    0 讨论(0)
提交回复
热议问题