Skip to content

Instantly share code, notes, and snippets.

@aprell
Last active October 7, 2019 13:14
Show Gist options
  • Save aprell/f53ced56d76a52ea4803df03a6cb65eb to your computer and use it in GitHub Desktop.
Save aprell/f53ced56d76a52ea4803df03a6cb65eb to your computer and use it in GitHub Desktop.
Another Lua gotcha
function f()
return 1, 2, 3
end
print(f()) -- 1 2 3
print(f(), 4) -- 1 4
print(4, f()) -- 4 1 2 3
@aprell
Copy link
Author

aprell commented Oct 7, 2019

Documented in Section 3.4 of the Lua Reference Manual:

If an expression is used as the last (or the only) element of a list of expressions, then no adjustment is made (unless the expression is enclosed in parentheses). In all other contexts, Lua adjusts the result list to one element, either discarding all values except the first one or adding a single nil if there are no values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment