WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   XML or not XML? (https://www.wowinterface.com/forums/showthread.php?t=14616)

Trefane 01-19-08 03:08 AM

XML or not XML?
 
I've read about addon writers saying that they preferred to create frames on the fly rather than use XML to statically create them when the addon loads.

- When they do it this way, do they completely generate the frame and its children with CreateFrame commands, or do they still include .XML templates and create frames based on those?
- What route do people here prefer?
- What are some good examples of this way of doing things?

Macniel 01-19-08 06:13 AM

XML is great if you are planing of reusing objects you can inherit the display and the values of XML-based frames to Lua- or other XML-based frames, you can't inherit frames created in Lua to other Lua frames.

So it can be useful to make your templates in XML and using them in Lua. I can imagine that a static XML template will reduce loading time 'cause they won't be interpreted by Lua and this is a important factor of big scaled AddOns : loading time after a ReloadUI.

I had used the XML+Lua construction in my AddOns, because there are WYSIWYG-XML-Editors for WoWXML (i'm lazy :D )

Malreth 01-19-08 09:42 AM

Quote:

Originally Posted by Macniel
XML is great if you are planing of reusing objects you can inherit the display and the values of XML-based frames to Lua- or other XML-based frames, you can't inherit frames created in Lua to other Lua frames.

But you can recreate the functionality of inherited frames by creating a factory function. You call it and it returns a new frame with all of the attributes that you desire. Since the function can take arguments, you can even essentially have template arguments for further flexibility with your template design.

Quote:

So it can be useful to make your templates in XML and using them in Lua. I can imagine that a static XML template will reduce loading time 'cause they won't be interpreted by Lua
I doubt it's that much of a difference. Either the XML for the frame has to be parsed and instantiated or the Lua has to be interpreted and then run. Six of one, half dozen of another.

Beladona 01-22-08 10:16 PM

The misconception that you can't make templates in Lua is technically false. In fact it could be argued that Lua allows truer templating than XML. The reason I say this is that in XML you must actually create your template as a virtual object. In Lua you create a function that generates a frame based on whatever settings you tell it to use, as Malreth mentioned. In essence both approaches allow templating, they just do so in different ways. Ultimately the decision to use XML or Lua is primarily about what the author prefers. Some people like the structured design that XML affords, while others like the procedural generation that Lua provides.

One thing I would say Lua affords over XML is the fact that XML is setup in advance with the objects you want. If you needed to make a frame during a certain event, you would have to use Lua to do so, as XML isn't something that can be executed at will. For this reason I prefer to do it ALL via Lua, as I then have full control of when, how, and specifically what gets created. Like Malreth said you can easily define all of your attributes by passing arguments to a factory function, which means MUCH more flexibility in the long run.


All times are GMT -6. The time now is 08:46 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI