lua-users home
lua-l archive

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

It works.
And I suggest t be a local variable.
Since unpack() do the trick, the code can be shorten to:

function (...)
  return unpack(..., "a")

Hope it helps.

On Tue, Nov 11, 2008 at 6:26 PM, Linker <> wrote:
I think you can try this:
  return unpack(t)

On Tue, Nov 11, 2008 at 17:44, Duncan Cross <> wrote:
On Tue, Nov 11, 2008 at 9:15 AM, Atry <> wrote:
I tried the follow code, but it seems not work.

function a(...) return ..., "a" end
assert(select(3, a(1, 2)) == "a");

Is there any way to append a argument to vararg without `{...}' and `unpack' ?

It looks like this is handled in the same way as "return func_call(), a" where func_call returns multiple values. I.e., an _expression_ that evaluates to a list is truncated to the first item when it is itself used as an item in a list (except the last). So, no, I don't think there is a way. Perhaps the Lua team could be convinced that '...' should be treated as a special case in this situation. (I'm not convinced myself, though, to be fair. It seems like there should either be a way to specify that a list of values should be expanded rather than truncated - I'm not sure what the syntax would be - or keep it consistent.)


Linker M Lin