lua-users home
lua-l archive

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




On Tue, Aug 2, 2022 at 2:09 PM Perry Smith <pedz@easesoftware.com> wrote:
This caught my attention in the reference manual in the Expressions section:

a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)

It seems that a function call used in an explist other than the last element is adjusted to return at most one value.  There is another similar example a few lines down.

Am I understanding that right?

If f() returns 0 values 'a' will be assigned a nil value. If f() returns more than one value all but the first value will be discarded. 'b' will be assigned the value of 'x' in all cases.

If f() is in the last position it the number of results will be adjusted to match the number of remaining variables (lvalues?) at the left hand side.

A similar thing happens when f() is in the last position of a parameter list, e.g. g(1,x,f()). All results of f() will be passed on to 'g', in any other position the number of results is adjusted to 1.


--