Functions
Normal
function name (arg)
-- function body
return 1 + 2 -- returining values is optional
end
name = function (param) print (param) end
Functions
can return multiple values.
function name (arg)
return 1, 2, 3, 4
end
The following are the same functions
.
function log(x)
print(x)
end
log = function(x) print(x) end
Higher order Functions
Taking Function as Argument
function name (para)
para("hi")
end
name(print)
Returning Functions
function name ()
return function (value) print (value) end
end
name()("hi")
Working with Tables
function name (table)
print(table.key)
end
name({key = 69}) -- valid
name{key = 69} -- valid