User:OrenBochman/Lua Functions & Variables
Functions
edit- Functions let you avoid duplication
- Functions can have arguments
- The code from the begining of a functions to the end - called the function's scope.
Calling functions
editcolour = getDivColour()
Defining functions
editThere are two types of functions
- Local functions for private use within the module
local function plural(word)
return word .. 's'
end
- Exported functions that can be used outside the module
local p = {}
function p.hello()
return 'hello'
end
return p
Local variable and global scope
editlocal p = {}
function p.hello()
return 'hello'
end
return p