lua-users home
lua-l archive

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


2015-07-16 13:35 GMT+02:00 zejian ju <juzejian@gmail.com>:
>
> 2015-07-16 10:40 GMT+08:00 Coda Highland <chighland@gmail.com>:
>>
>>
>> It's pretty simple: (f()) is an expression, not a function call
>> (though it of course CONTAINS a function call), and expressions always
>> return a single value. You could also say f() + 0.
>>
>> /s/ Adam
>>
> Thank you for your explanation. In fact I have the same question, not only
> for parenthesized function call and ellipsis, also for the function call and
> ellipsis in the middle of an expression list.

The general rule is that an expression evaluates to one value, and an
expression list (aka explist) evaluates to as many values as supplied.
In function calls, return lists, parameter lists and table constructors,
explists are used. However, when building up an explist, only the last
item in it may be another explist, the others must be an expression.
Any explist appearing before that is silently truncated to one item
(or expanded to the one item `nil` if it is empty).

Three places in the manual stating all that, sort of, when read together,
are:

§3.3.3
If the list of expressions ends with a function call, then all values
returned by that call enter the list of values, before the adjustment

§3.4
Any expression enclosed in parentheses always results in only one value.

§3.4.11
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.