As to why you would use one method over another. There is no clear reason I can give you. It is, IMHO a matter of convention and preference.
I mostly write my modules using dot (.) notation, because it rarely makes sense for my functions to be methods and I don’t need them to have a reference to the module. i.e. They are each independent functions that don’t really care about the module or any of the other functions.
However, if I have a module, where the methods are going to cross call I might use colon ( notation.
Note. Even when I know the object will be called using colon (:) notation, I typically specify using dot (.) notation:
local obj = display.newCircle( 10, 10, 10 ) function obj.touch( self, event ) ... body of touch here end obj:addEventListener( "touch" )
On a last note, if you’re thinking about private versus non-private construction of modules, Lua does not supply any concept of private. So, the only one way (that I know) to achieve truly private functions in a module:
-- Forward Declarations of private functions (for visibility sake) local someFunction local aPrivateFunction local worker = {} -- Definition of module functions and merthods function worker.publicFunction( a, b ) return someFunction( a ) + aPrivateFunction(b) end function worker:publicMethod( a, b ) return self.publicFunction( a, b ) end -- Definition of private functions (I like to put them last and before the module return) someFunction = function( arg ) return 10 \* arg end aPrivateFunction = function( arg ) return arg/10 end return worker
If I can read my own code, this:
local worker = require "worker" --assumes I saved above in worker.lua worker:publicMethod(1,100)
Should print: 20