lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Currently, Lua has strict implicit rules with respect to the adjustment of multiple values: they are not adjusted if they are the last or the only element in a list of expressions, and adjusted to to one value in every other case.

If, for example, one would like to forward just two values from a function returning more than two, one has to use intermediate variables:

local a, b = foo()
bar(a, b)

One can also not pass multiple values and then some other values to another function:

qux(foo(), bar()) -- no way to pass multiple return values from both foo and bar

I propose adding a way for the user to say "I want to adjust to this number values" and "I want to pass all of them". While syntax is debatable as ever, something like this could work:

For function calls, allow an optional "adjuster" in the form :n, where n is either a number or *, meaning "n values" and "all values" correspondingly. Then the examples above could be re-written as follows:

bar(foo():2)
qux(foo():*, bar())

For vararg expressions, a similar adjuster could be used, even though it looks quite strange, so better syntax is probably possible:

bar(...:2)
qux(...:*, bar())

An open question here is whether the adjuster should be static or dynamic, in the latter case the n being a variable.

Cheers,
V.