Thread Tools Display Modes
01-12-15, 02:15 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Frames: XML vs LUA?

So far in my addon, I've created all my frame/UI elements using LUA. I've been wondering, is there a substantial difference with using XML over LUA? I've read that XML might be faster, but haven't found any confirmation of this. Anyone know?
  Reply With Quote
01-12-15, 02:33 PM   #2
Malakahh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 30
The most substantial thing I'm aware of, is that XML is required if you wish to CREATE templates. You can still use templates through lua. Other than that, I don't believe there's much difference.

Lua isn't an acronym btw, it means moon. :P
  Reply With Quote
01-12-15, 02:42 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,878
XML is only required if you want to use the secure templates, other than that lua works fine and is easier to debug if nothing else.

You can mimic templates in lua.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
01-12-15, 03:04 PM   #4
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
Quoting someone I consider a WoW guru (Gello), if not that, at least he spent a lot of time teaching coding to people interested in learning:
XML is more optimized to load/create frames and their attributes, and has some tags like forceAlpha that would be more cumbersome/inefficient to do in lua. Some XML is required if you ever make a hybrid scrollframe. Element stacking is much easier in XML too; not just from the nature of the code but tags like useParentLevel and textureSubLevel allow you to define how your stuff layers without micromanaging every detail or creating unnecessary frames. XML also has some recent tags like parentArray that makes it easy to reference all your stuff in lua too.

But lua-only addons are perfectly acceptable too. It's not more "efficient" to do it one way or the other once your stuff actually loads.

For smaller projects (or even bigger ones without many UI elements), I'll usually do everything in lua. For bigger projects with many UI elements, XML is my personal preference.
  Reply With Quote
01-12-15, 03:54 PM   #5
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Thanks for the info guys!
  Reply With Quote
01-12-15, 06:04 PM   #6
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Banknorris View Post
Quoting someone I consider a WoW guru (Gello), if not that, at least he spent a lot of time teaching coding to people interested in learning:
I've made a HybridScrollFrame without using XML...
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
01-12-15, 08:09 PM   #7
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I like the concept behind using XML for frames, in that the language format is structured to actually represent the logical structure of the elements, and that it clearly separates elements from function. (subject to major abuse of technical terms) But! It simply requires too much effort to get things done compared to doing it in Lua.

I started working on some code that would essentially let you replace XML templates with Lua tables, but was not sure whether it'd be worth it in the end.
__________________
Grab your sword and fight the Horde!

Last edited by Lombra : 01-12-15 at 08:13 PM.
  Reply With Quote
01-12-15, 11:15 PM   #8
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
All can be done in lua, include the elements that based on secure templates. But it also requires plenty of works to build a whole framework instead of the xml template system.

Here is an example lib IGAS, it's created without xml templates, it's based on an oop system(PLoop) so I can make widget classes instead of the xml template. There are widget classes such as TreeView, LayoutPanel, CodeEditor, UnitFrame, UnitPanel(as the raid panel), ActionButton and many others, all be created based on other widget classes.

With the class system, the code will be clear for reading. To create a form in the pic :

Click image for larger version

Name:	test.png
Views:	793
Size:	102.0 KB
ID:	8435

Lua Code:
  1. -- Import the namespace
  2. import "System.Widget"
  3.  
  4. -- Form is a class that defined in the System.Widget namespace
  5. -- It's a common widget element that used to contains others
  6. local form = Form ("TestF")
  7. -- Caption is the text that displayed on the form header
  8. form.Caption = "Tiny Editor"
  9. -- Message is the text that displayed on the bottom of the form
  10. form.Message = "Input some code and press run"
  11. form.Size = Size(600, 500)
  12.  
  13. -- lua code editor
  14. local editor = CodeEditor ("Editor", form)
  15. editor.Location = {
  16.   AnchorPoint("TOPLEFT", 4, -26),
  17.   AnchorPoint("BOTTOMRIGHT", -4, 56),
  18. }
  19.  
  20. -- the run button
  21. local btn = NormalButton ("Run", form)
  22. btn.Style = "Classic"
  23. btn.Size = Size(100, 24)
  24. btn.Text = "Run"
  25. btn.Location = {
  26.   AnchorPoint("BOTTOMRIGHT", -4, 24),
  27. }
  28.  
  29. -- Run the code when click the button
  30. function btn:OnClick()
  31.   pcall( loadstring (editor.Text) )
  32. end

With the oop system, I also can define a whole new class for the above example:

Lua Code:
  1. -- Import the System.Widget namespace
  2. import "System.Widget"
  3.  
  4. -- Create a new class that inherit from the Form
  5. class "CodeForm"
  6.   inherit "Form"
  7.  
  8.   local function run_OnClick(self)
  9.     pcall( loadstring (self.Parent.Editor.Text) )
  10.   end
  11.  
  12.   -- Init the CodeForm
  13.   local function InitializeComponent(self)    
  14.     self.Caption = "Tiny Editor"
  15.     self.Message = "Input some code and press run"
  16.     self.Size = Size(600, 500)
  17.  
  18.     -- lua code editor
  19.     local editor = CodeEditor ("Editor", self)
  20.     editor.Location = {
  21.       AnchorPoint("TOPLEFT", 4, -26),
  22.       AnchorPoint("BOTTOMRIGHT", -4, 56),
  23.     }
  24.  
  25.     -- the run button
  26.     local btn = NormalButton ("Run", self)
  27.     btn.Style = "Classic"
  28.     btn.Size = Size(100, 24)
  29.     btn.Text = "Run"
  30.     btn.Location = {
  31.       AnchorPoint("BOTTOMRIGHT", -4, 24),
  32.     }
  33.  
  34.     btn.OnClick = btn.OnClick + run_OnClick
  35.   end
  36.  
  37.   -- The Constructor
  38.   function CodeForm(self, ...)
  39.     -- call super class's constructor
  40.     Super(self, ...)
  41.  
  42.     InitializeComponent(self)
  43.   end
  44. -- End the definition of the class
  45. endclass "CodeForm"
  46.  
  47. -- Create an instance of the CodeForm
  48. local form = CodeForm("TestForm")
  49. -- make sure the form is shown
  50. form.Visible = true

It may not be a good example because the whole IGAS lib is a big one and the syntax of the PLoop is too special for common addons.

The xml is not that bad, it's very clear to show the structure of the whole frames, but it's not good at the inheritance. Here is some from the MainMenuBarBagButtons.xml.

Code:
	<Frame name="ItemAnimTemplate" virtual="true">
                 <Scripts>
			<OnLoad function="ItemAnim_OnLoad"/>
			<OnEvent function="ItemAnim_OnEvent"/>
		</Scripts>
        </Frame>

         <CheckButton name="BagSlotButtonTemplate" inherits="ItemButtonTemplate, ItemAnimTemplate" virtual="true">
		<Size x="30" y="30"/>
		<Scripts>
			<OnLoad>
				ItemAnim_OnLoad(self)
				PaperDollItemSlotButton_OnLoad(self);
                .......
So the BagSlotButtonTemplate should call ItemAnim_OnLoad itself, that means the child template must know what the super template had done.

It's not a big problem, but I just don't like it.
  Reply With Quote
01-13-15, 02:46 AM   #9
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I hate XML because of its poor "debugging capabilities".
  Reply With Quote
01-13-15, 07:36 AM   #10
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Personally, I prefer lua, because:
a) While I haven't touched these XMLs in some time, I remember everything having to be enclosed with <Points></Points> and then inside it every element is <Point>...</Point>. That's a lot of text that I'd rather live without.
b) Representing your frames as being inside one another is all good and fine, but I like having all the important init details of a frame in one place, rather than having to scroll a thousand lines between its size and its backdrop because there is literally an entire add-on's frame structure stuck between them.
c) Templates are good and fine, but I prefer functions
d) Debugging...
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Frames: XML vs LUA?


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