Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 413
Antoine Richermoz Avatar asked Aug 26 '17 08:08

Antoine Richermoz


2 Answers

You can't do it in one line because f2(f1(),c) adjusts the results returned by f1 to a single value.

like image 170
lhf Avatar answered Oct 14 '22 04:10

lhf


You could use intermediate results

local a, b = f1()
f2(a, b, c)
like image 31
Brent Easton Avatar answered Oct 14 '22 04:10

Brent Easton