Using Modules
- A module is some code that can be loaded through the "require" statement
- Can be a combination of Lua and C code
- The "require" statement returns a table
- The table acts as a namespace
- The table contains constants, functions, etc.
- The standard libraries are modules
An example of using the math library
local math = require "math" local table1 = {} for i = 1, 10 do table1[i] = math.random(1, 200) print(table1[i]) end
- require cannot pass arguments
- This restriction is because the structures used are a normal part of the language
- You can easily create functions in the module that will allow the passing of arguments