lua-users home
lua-l archive

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


I think you can try this:
function(...)
  t={...}
  t[#t+1]="a"
  return unpack(t)
end



On Tue, Nov 11, 2008 at 17:44, Duncan Cross <duncan.cross@gmail.com> wrote:
On Tue, Nov 11, 2008 at 9:15 AM, Atry <pop.atry@gmail.com> 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.)

-Duncan



--
Regards,
Linker M Lin
linker.m.lin@gmail.com