Dealing with templates and OOP
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"> Lua Code:
If I write Lua Code:
Lua Code:
I tried to not put self in the signature, just leaving it without any params: Lua Code:
Lua Code:
attempt to call method 'SetWidgetScript' (a nil value) Can you help me? |
The way Lua handles obj.method() vs obj:method() is simple, but not straightforward.
When calling a function, obj:method(...) is the same as obj.method(obj,...). When defining a function, obj:method(...) is the same as obj.method(self,...). Lua will handle mixing these syntaxes as long as you take the above rule in mind. If you call obj.method(frame), a function defined as obj:method() will receive frame and put it in self. One way or another, you need a reference to your frame to work on it. The WoW API doesn't set any globals when a frame script runs. The way I would implement your code with this in mind and make room for easier expansion: Lua Code:
OnLoad Handler: Code:
LibListView.New(self) Lua Code:
One major change was to separate your static functions and instanced data. The frame methods were moved to their own metatable and are injected into the frame. As the frame is basically a table itself, data values are written directly into it. |
All times are GMT -6. The time now is 07:25 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI