lua-users home
lua-l archive

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


On Wed, Jun 15, 2011 at 8:57 AM, Fredrik Widlund
<fredrik.widlund@qbrick.com> wrote:
> Hi,
>
> Could someone explain if the following is by design:
> Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
>> a={1,2,3}
>> b={4,5,6}
>> c={unpack(a), unpack(b)}
>> print(table.concat(c, ","))
> 1,4,5,6
>
> It seems the second unpack starts "writing" its members to position i+1 and thus overwrites the members of the first unpack? Is this really correct behaviour?

See the manual [1].

"If a vararg expression is used inside another expression or in the
middle of a list of expressions, then its return list is adjusted to
one element. If the expression is used as the last element of a list
of expressions, then no adjustment is made (unless that last
expression is enclosed in parentheses)."

[1] http://www.lua.org/work/doc/manual.html#3.4.9

-- 
- Patrick Donnelly