Ale*_* V. 2 lua variadic-functions
function f(...)
return ...
end
Run Code Online (Sandbox Code Playgroud)
我称之为:
f()
Run Code Online (Sandbox Code Playgroud)
例
a = f()
print(a) -- echoes 'nil', same as print(nil)
Run Code Online (Sandbox Code Playgroud)
但
print(f()) -- echoes newline, same as print(), that is, no args
t = {f()} -- same as t = {}
Run Code Online (Sandbox Code Playgroud)
那么,f()返回什么?
更新:不知道函数可以返回'void',同时发现这个http://lua-users.org/lists/lua-l/2011-09/msg00289.html.
它返回您调用它的所有参数.
f() -- has no parameter, returns nothing
Run Code Online (Sandbox Code Playgroud)
如果您使用的值少于变量值,即
local a, b = 3
local c
Run Code Online (Sandbox Code Playgroud)
然后,这将最终以b和c为零.
另一方面,这将做一些事情:
f(1) -- returns 1
f(1, 2, 3) -- returns 1, 2 and 3
local t = {f(1, 2, 3)} -- table with the values 1, 2 and 3
Run Code Online (Sandbox Code Playgroud)