Your second example is valid syntax and identical to the second function definition in the first example.
Writing:
In the Module “modname.lua”
module(..., package.seeall)
function modname.funcname() end
-- is equivalent to
function funcname() end
as “module” is the table of the module itself and its functions are entries in the table
You can validate this by doing:
module(..., package.seeall)
function funcname() end
print(funcname)
print(modname.funcname)
which will show the identical value.
As will:
module(..., package.seeall)
function modname.funcname() end
print(funcname)
print(modname.funcname)
If you write it like this:
module(..., package.seeall)
funcname = function() end
modname.funcname = function() end
You see that you actually access the “funcname” inside the table “modname”.
This is different to:
module(..., package.seeall)
local funcname = function() end
which will not add the “funcname” to the modname table.
The “modname” table is generated because of calling “module()”.
To come back to “:”
module(..., package.seeall)
function funcname(self, x) print(self) end
-- is identical to
function modname.funcname(self,x) print(self) end
-- is identical to
function modname:funcname(x) print(self) end
The colon is just “magic” for inserting the self as hidden parameter.
I hope that is answering your questions now!
[import]uid: 6928 topic_id: 1341 reply_id: 3641[/import]