Function Definitions

A function definition is an executable expression,whose value has type functio Function definitions can be nested, or used in assignment statements.

function funcname ( ... ) BLOCK end
function funcname ( NAME {, NAME} [, ...] ) BLOCK end

Syntactic sugar for function definitions and their equivalents:

function f (ARGS)   … f = function (ARGS) …
function v.f (ARGS) … v.f = function (ARGS) …
function v:f (ARGS) … v.f = function (self, ARGS) …

Whenever Lua executes the function definition, its upvalues are fixed, and the function is instantiated (or closed). This instance (or closure) is the final value of the expression.Different instances of the same function may have different upvalues.

An adjustment is made to the argument list if required. Parameters act as local variables.Results are returned using the return statement, otherwise the function returns with no results.

If the function is a vararg function (denoted by the ‘…’at the end of its parameter list,) it collects all extra arguments into an implicit table parameter, called arg, with a field n whose value is the number of extra arguments (found at positions 1, 2,…, n.)