Syntax
- funcname = function(paramA, paramB, ...) body; return exprlist end -- a simple function
- function funcname(paramA, paramB, ...) body; return exprlist end -- shorthand for above
- local funcname = function(paramA, paramB, ...) body; return exprlist end -- a lambda
- local funcname; funcname = function(paramA, paramB, ...) body; return exprlist end -- lambda that can do recursive calls
- local function funcname(paramA, paramB, ...) body; return exprlist end -- shorthand for above
- funcname(paramA, paramB, ...) -- call a function
- local var = var or "Default" -- a default parameter
- return nil, "error messages" -- standard way to abort with an error
Functions are usually set with function a(b,c) ... end
and rarely with setting a variable to an anonymous function (a = function(a,b) ... end
). The opposite is true when passing functions as parameters, anonymous functions are mostly used, and normal functions aren't used as often.