Unpack() with others in a print()

Discuss any general programming issues here
Post Reply
User avatar
lazi
Posts: 627
Joined: Thu Feb 24, 2011 11:08 pm

Unpack() with others in a print()

Post 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

???
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

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

Post 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
Post Reply