lua-users home
lua-l archive

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


Hello!
I've found a strange behavior of a mutliret function if I call this function multiple times within a single statement.
This may be a known issue or an expected behavior, but I was not able to find anything about it.

I created a function that returns multiple values (I tested for two and three values), then I call them in a single statement and only the first returned value from the first function is included into the statement's results, while all values returned by the second call are included.

Here is an example:

```
function test()
   return 3, 2
end

print(test(), test())
```

The print function will receive only three argument, while I expect it to receive four. As a result, it prints this:
```
3 3 2
```

While I expect it to print "3 2 3 2". This happens for both Lua and C functions that return multiple results. If a statement returns only one call to a function and an additional value, then it also omits all values except the first:

```
print(test(), 3) -- > prints 3 3
```

If a statement has an explicit value on the first place, it handles all returned values:
```
print(3, test()) -- > prints 3 3 2
-- this also works fine:
print(3, 4, test()) -- > prints 3 4 3 2 
```

Is this an expected behavior or a bug? I used Lua 5.3.4 to test, it also works on the demo page at https://www.lua.org/cgi-bin/demo

Best regards,
Ivan.