Creating Modules
- Modules can be created as tables containing functions etc.
A example that creates a new module
newModule = {} local masterTable = {} local i = 1 function newModule.addString(inputVariable) if type(inputVariable) ~= "string" then print("Error - input is not a string") else masterTable[i] = inputVariable i = i + 1 end end function newModule.printStrings() for j = 1, i-1 do print(masterTable[j]) end end return newModule
An example of loading and run the new module
local testModule = require "moduleSample" testModule.addString("This is the first string") testModule.printStrings()