简体   繁体   English

Lua返回多个值作为参数

[英]Lua return multiple values as arguments

I have a function (that I cannot change) returning multiple values : 我有一个函数(我无法更改)返回多个值:

function f1()
    ...
    return a, b
end

and another function (that I cannot change) taking multiple arguments : 和另一个带有多个参数的函数(我无法改变):

function f2(x, y, z)
    ...
end

is there a way to do : 有办法吗?

f2(f1(), c)

and have x be a , y be b and z be c ? 并且xaybzc

You could use intermediate results 您可以使用中间结果

local a, b = f1()
f2(a, b, c)

您不能在一行中执行此操作,因为f2(f1(),c)f1返回的结果调整为单个值。

You can use a table as a helper: 您可以使用表作为帮助程序:

tbl={f1()}
tbl[3]=c
f2(unpack(tbl))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM