lua-users home
lua-l archive

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


No, unpack{...,"a"} does not work:

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> function append(...)
>> return unpack{..., "a"}
>> end
> print(append("b", "c")) --> b  c  a ?
b       a

Manipulating varargs in Lua is often inelegant, and writing a simple C function to do it may be the better option.

On Tue, Nov 11, 2008 at 11:39 AM, Jun Wu <idearet@gmail.com> wrote:
Sorry. But I have mistyped  ...
unpack{ ... , "a" } just works :p

Thanks for the detailed explaination all the same!


On Tue, Nov 11, 2008 at 7:26 PM, Duncan Cross <duncan.cross@gmail.com> wrote:


On Tue, Nov 11, 2008 at 11:14 AM, Jun Wu <idearet@gmail.com> wrote:
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")
end

Hope it helps.

No, it can't - that is the point, you cannot just use "..., something" and expect it to add "something" onto the end.

Also, using unpack() directly on "..." will not work. It is expecting a table only.

Finally, the technique of putting "..." into a temporary table and using unpack on it was already mentioned in the original post. Atry's already aware of it and was asking if any better alternative methods exist.