[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: strangeness in handling tables**
**From**: Peter Cawley <lua@...>
**Date**: Sat, 20 Jun 2009 22:44:51 +0100

On Sat, Jun 20, 2009 at 10:21 PM, bb<bblochl@arcor.de> wrote:
> Is there any explanation for that behaviour?
>
> Regards BB
In table constructors, every element (with the except of the last) is
adjusted to one return value. For expressions with more than one
return value, the values after the 1st are discarded, and for
expressions with no return value, they are adjusted up to one return
value by adding nils. A similar thing happens when assigning the
result of an expression to a (list of) values; the number of results
is adjusted to the number of values:
> a, b, c = 1, 2, 3
> = a, b, c
1 2 3
> a, b, c = math.sin(math.pi/2)
> =a, b, c
1 nil nil
> a, b, c = (function() return 1, 2, 3, 4, 5 end)()
> =a, b, c
1 2 3
As previously stated, in table constructors, each expression except
the final expression is adjusted to exactly one result. The final
expression is not adjusted at all - if it returns no values, then it
adds to values to the table.