Lua Programming/How to Lua/function

Functions in lua are first classEdit

Functions in lua are first class. This means that the function can be stored in a variable or table and can be returned by other functions.

Functions use global scopeEdit

Functions in lua are anonymousEdit

Function arguments should be enclosed in parentheses and separated by commasEdit

Parentheses for function arguments can be omitted in some circumstancesEdit

The arguments for function calls are normally enclose in parentheses. If the function call has only one argument and this is either a string or a table constructor, then the parentheses can be omitted:

print "Hello World"    -- We have omitted parentheses from the literal string

Note that if a function has no arguments, then the empty list must be enclosed in parentheses to indicate that this a function call:

print()    -- We must use parentheses if the argument list is empty

Spaces and other whitespace characters are not allowed in function namesEdit

See alsoEdit

builtin functions

Last modified on 8 March 2011, at 17:43