This is the first time I try to apply OOP in Lua. My goal is to create a template as if it were an object, without using the mixin.
XML code:
Code:
<Frame name="TemplateListViewTemplate" virtual="true">
<Scripts>
<OnLoad>
self = LibUnitScanListView:New(self)
</OnLoad>
</Scripts>
</Frame>
Lua code:
Lua Code:
LibListView = {}
function LibListView:New(self)
local listviewmt = {
buttons = {},
data = {},
--more methods and functions
SetWidgetScript = function(words) print(words) end,
}
setmetatable(self, { __index = setmetatable(listviewmt, getmetatable(self)) })
end
If I write
Lua Code:
self = LibListView:New(self)
inside <OnLoasd> tag the code works fine. At this point, I would like to make sure that the class is created without passing
self as a parameter: in short, using the wording
Lua Code:
listview = LibListView:New()
to make the code more elegant.
I tried to not put
self in the signature, just leaving it without any params:
Lua Code:
function LibListView:New()
At this point an error emerges:
Lua Code:
listview = CreateFrame("Frame","listview",UIParent,"TemplateListViewTemplate")
listview:SetSize(150, 100)
listview:SetPoint("TOPLEFT",50,-75)
listview:SetWidgetScript("Hello World")
returns this error:
attempt to call method 'SetWidgetScript' (a nil value)
Can you help me?