First of all you should decide either using . or :, but not a mixture (where not needed).
:
: is used for the kind of object-oriented approach where you define a "class" and create objects of that class, and then you call functions of that object referencing it via self.
-> Where the "class" is only a table which the objects use via metatables to "inherit the functions and attributes of the parent class table".
Classes in ESO lua are defined using ZO_Object:Subclass() e.g. like this:
Lua Code:
local ZO_PlatformStyleManager = ZO_Object:Subclass()
function ZO_PlatformStyleManager:New()
local obj = ZO_Object.New(self)
obj:Initialize()
return obj
end
ZO_PlatformStyleManager is the "class", and
this function creates an object "PLATFORM_STYLE_MANAGER " of that class:
Lua Code:
local PLATFORM_STYLE_MANAGER = ZO_PlatformStyleManager:New()
objects using the : to call functions are able to use the variable "self" in their function code to reference the object variable.
Lua Code:
function ZO_PlatformStyleManager:Add(object)
table.insert(self.objects, object)
end
self.objects will be the table "objects" at self, where self is the created object of class ZO_PlatformStyleManager.
As the created object of ZO_PlatformStyleManager is PLATFORM_STYLE_MANAGER (See above), self.objects will be PLATFORM_STYLE_MANAGER .objects then.
If you do not plan to create a class and have an object, or even multiple objects (like a logger library/addon creates multiple loggers with base function ":log" [defined at the super class] e.g., but different functions for each logger e.g. :warning, :error [defined at each individual logger]) you shouldn't use :
That's my opinion so feel free to do like you wish and prefer
.
. just is using a "table", no object-oriented approach, no metatables.
You define a table
and define variables, subtables, function and assign it to the table using the .
Lua Code:
addonName.subTable = {}
addonName.var1 = "Hello world"
function addonName.myFunc(param1) end
variables using the . to call functions are not able to use the variable "self" in their function code to reference the table variable.
If you want to specify any object/table you reference to, you need to name it by it's name.
Lua Code:
function addonName.myFunc(param1)
--self is not given here! If you want to reference variables), just use the variable name
end
The object example function "ZO_PlatformStyleManager:Add(object)" from above, using the :, would look like this using the . instead:
Lua Code:
function ZO_PlatformStyleManager.Add(objectVariableOfClass, object)
table.insert(objectVariableOfClass.objects, object)
end
The 1st parameter of the function would be the created object of the class, and you cannot use self anymore, but need to use this passed in parameter then.
The call to the function would not be this anymore:
Lua Code:
local CreatedObjectOfZO_PlatformStyle = ZO_PlatformStyle:New(param1, param2, ...)
PLATFORM_STYLE_MANAGER:Add(CreatedObjectOfZO_PlatformStyle)
But this:
Lua Code:
local CreatedObjectOfZO_PlatformStyle = ZO_PlatformStyle:New(param1, param2, ...)
PLATFORM_STYLE_MANAGER.Add(PLATFORM_STYLE_MANAGER, CreatedObjectOfZO_PlatformStyle)
Again this is only my opinion:
You should stick to using the . way and normal tables to keep it easy, where possible.
But this is totally up to you. You can create your addon as a class + object, or even without deifning it as a class (ZO_Object:Subclass()) you ca still use the : .
But it does not make that much sense, or at least I did not get why it would so far