The module feature is a feature which can call and use a program written on other files.
Like a class, you can modularize Lua script based on their functions.
-- Store the feature of the module in module_1 local module_1 = require "module_1" -- Call a function in module_1 print(module_1.GetName()) print(module_1.GetVector())
-- Return the name of its file name local function GetName() return "module_1" end -- Return Vector3.__new(0,100,0) local function GetVector() return Vector3.__new(0,100,0) end -- required for using IntelliSense (predictive input) in VScode return { GetName = GetName, GetVector = GetVector }
module_1 (0,100,0)
local module_1 = require "module_1" local test1 = module_1.new(50,1) local test2 = module_1.new(100,2) test1:pp() -- You can ommit the self argument by usnig a colon. Same as "test1.pp(test1)" test2:pp()
local module_1 = {} -- This name can be anything module_1.new = function(_x,_y) -- create a table dynamically with the "new function" local obj = {} obj.x = _x obj.y = _y obj.pp = function(self) print(string.format("(%d,%d)", self.x, self.y)) end return obj end return module_1