Hi All,
Hopefully an easy question for someone in the know… im trying to work out how best to create modules to simplify my code. I know that the module package see all thing seems to be way out dated and the prefered way is to decalare a local table to wrap a module in?
assuming that is now ‘the way’ to do modules, i have a question about the difference between this:
module1 :
local mod1 = { x = 1 } function mod1:doSomething1() print ("doingSomething") end return mod1
module2
local mod2 = { x = 2 } function mod2.doSomething2() print ("doingSomethingAgain") end return mod2
What is the difference between using the . or using the : ?
in main.lua it doesnt seem to make a difference. i.e. the below all give the same results.
Just hoping someone can tell me if I am doing this right and if there is a difference or not?
thanks for your help
local m1 = require("module1") local m2 = require("module2") m1.doSomething1() m2.doSomething2() m1:doSomething1() m2:doSomething2() m1:doSomething1() m2.doSomething2() print (m1.x) print (m2.x)