Function Calls

A function call in Lua has the following syntax :

varorfunc ( {EXP1, } EXP )

and alternative forms:

v:name(...)

v.name(v,...)

Call a method (v is evaluated once)

f{...}

f({...})

Call f with a single new table

f’...’

f(’...’)

Call f with a single literal string

f"..."

f(’...’)

Call f with a single literal string

f[[...]]

f(’...’)

Call f with a single literal string

First, varorfunc is evaluated. If its value has type function, then this function is called, with the given arguments.Otherwise, the function tag method is called, having as first parameter the value of varorfunc, and then the original call arguments.

All argument expressions are evaluated before the call

A function can return any number of results. The number of results must be adjusted before they are used. If the function is called as a statement, all returned values are discarded (list adjusted to 0.)

If a function is called as an argument in a place that needs a single value (EXP1 ) then its return list is adjusted to 1. If the function is called in a place that can hold many values (EXP), then no adjustment is made. The only places that can hold many values is the last (or the only) expression in an assignment, in an argument list, or in the return statement.