Lua also supports multiple return values: you can, for example, write the following:
function foo() return 1, 2, 3 end a, b, c, d = foo()
after execution, a, b, c will hold the values 1, 2, 3, and d will be equal to nil. Similarly, you can do the following:
function bar() return true, 2, 3 end if bar() then -- do something intelligent end
the if statement in this case only works with the first returned value - if you need other values, you will have to store them in variables, as usual:
a, b, c = bar() if a then -- do something intelligent end
so you see: in Lua, all return values that are not needed are thrown away (for example, 2, 3 in the if example).
Henko
source share