Frame custom function
I created a template like this
Code:
<Frame name="My_GroupBox" toplevel="true" virtual="true"> Lua Code:
EDIT: Maybe this can be a solution? Lua Code:
|
These days it would be done using a Mixin eg.
XML Code:
<Button name="AchievementFullSearchResultsButtonTemplate" mixin="AchievementFullSearchResultsButtonMixin" virtual="true"> Lua Code:
This would "apply" any function defined in the AchievementFullSearchResultsButtonMixin table as a method of the button when the frame using the template is created. |
Widget handlers instead, in a virtual template can be set in lua or only via xml?
|
I'm not sure I really understand the question but maybe the answer is, if you have just an OnLoad script in XML then you can set anything in that using lua including other SetScripts.
|
For the sake of clean code, I loaded the Lua scripts like this
Code:
<OnLoad> attempt to call method 'CreateList' (a nil value) |
the <Script file="luascript.lua"/> goes in the XML file before you add any <Frame .. tags etc.
self:CreateList wont exists unless the frame has a Mixin defined in lua, most likely in luascript.lua luascript.lua Code:
BenalishListSomethingFrameMixin = {} Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd"> |
Works also in WotLK classic?
|
Should work in all versions.
|
You can use function or method attributes to refer to a Lua function.
This calls MyFrame_OnLoad() from the global environment. Code:
<Scripts> This calls :OnLoad() from the frame's table. Useful for calling functions from inherited mixins. Code:
<Scripts> For more information on handler tags, see WoWPedia: XML/Scripts. PS: <Backdrop> tags are depreciated and no longer work. You need to inherit BackdropTemplate and call :SetBackdrop() with your custom backdrop. |
Is it possible to do the same thing the old-fashioned way, using metatables?
|
I'm not sure what you mean by "the old-fashioned way" but I'm pretty sure it didn't use metatables. More likely, anything that needed to be run from XML or actioned the frame was defined as a global function.
|
The problem of templates is the template "class" you create doesn't exist as an object accessible by Lua. You need to create an OnLoad handler and register it for your template to call when instantiated. At that time, your handler is passed a reference to the instanced frame to act on.
What a mixin does is take an existing table and copy its contents into the instantiated frame's table, making every function defined by the mixin available immediately as a method of the frame. Lua Code:
Code:
<Frame name="MyTemplate" mixin="MyTemplateMixin" virtual="true"> Using metatables for templates has never been a thing. Historically, people have defined global functions and had frames call them. Even that was short-lived once the ability to create frames from Lua was implemented. XML has always been a pain for debugging and is rarely used anymore. |
All times are GMT -6. The time now is 09:18 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI