Page 1 of 1

Unpack() with others in a print()

Posted: Mon Sep 07, 2015 8:47 am
by lazi
Hi!

I have not seen any reason why are the following print commands makes different output:

a={1,2,3,4,5}

nprint(unpack(a),"*") -> result: 1 *

while

nprint("*",unpack(a)) -> result: * 1 2 3 4 5

???

Re: Unpack() with others in a print()

Posted: Mon Sep 07, 2015 3:34 pm
by airsoftsoftwair
That's the way Lua adjusts function return values. From the Lua book:
Lua always adjusts the number of results from a function to the circumstances of the call. When we call a function as a statement, Lua discards all of its results. When we use a call as an expression, Lua keeps only the first result. We get all results only when the call is the last (or the only) expression in a list of expressions.
See here: http://www.lua.org/pil/5.1.html