6

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 ?

3 Answers3

2

You could use intermediate results

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

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

lhf
  • 70,581
  • 9
  • 108
  • 149
1

You can use a table as a helper:

tbl={f1()}
tbl[3]=c
f2(unpack(tbl))
macroland
  • 973
  • 9
  • 27