Thursday, January 10, 2008

A little bit of Lua weirdness

Quoting from Beginning Lua Programming:

"If a function call is the last (or only) expression in a value list, then all (if any) values returned by the function are used. If a function call is in a value list but is not the last expression, then its first return value (or nil if it returns nothing) is used and any remaining return values are discarded."


So, in the case of function Do Nothing () end:
> print(1, DoNothing())
1

> print (DoNothing(), 2)
nil

and

> print (ReturnArgs(1,2,3), ReturnArgs("a", "b", "c"))
1 a b c

No comments: