Thread Tools Display Modes
01-19-08, 03:08 AM   #1
Trefane
A Murloc Raider
Join Date: Aug 2007
Posts: 7
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?
  Reply With Quote
01-19-08, 06:13 AM   #2
Macniel
A Fallenroot Satyr
 
Macniel's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 26
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 )
  Reply With Quote
01-19-08, 09:42 AM   #3
Malreth
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 9
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.

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.
  Reply With Quote
01-22-08, 10:16 PM   #4
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
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.

Last edited by Beladona : 01-22-08 at 10:18 PM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » XML or not XML?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off