Skip to content

Parser notes

Dibyendu Majumdar edited this page Oct 3, 2020 · 9 revisions

Lua Parser Notes

Handling multiple return values from function calls

Lua functions return multiple values. The caller has to decide how many values to accept.

  1. If the function call is the last expression in a function argument list, or in a return statement, or in a table constructor then we have to allow unlimited values.

  2. If the function call is in an assignment statement (including local declaration) and is the last expression, then the number of return values to accept is equal to corresponding variable plus any excess variables.

  3. In all other cases the function return values are truncated to 1 result.

  4. If a function call is surrounded by parens then it truncates result to 1 value.

handling _ENV

Normally up-values reference local variables in an enclosing function. However _ENV is a special case as it doesn't exist as a local variable in any scope and yet we need to create an up-value for it when globals are accessed. We also need to allow for the user defining a local _ENV in some scope, which would then override the default _ENV.

The special case handling of _ENV was addressed in issue #35.

Clone this wiki locally