Thread Tools Display Modes
03-19-13, 03:57 PM   #1
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
H: Why XML and why LUA?

Greetings,

So ive read some books and some topics about LUA and XML. According to most information, LUA should be used for the behavior of an AddOn while XML is used for the Layout(Graphics) - however both can be used for either.

Now my question would be;

In cases like moving a frame, why is
<OnDragStart> self:StartMoving() </OnDragStart>
<OnDragStop> self:StopMovingOrSizing() </OnDragStop>

used over the easy LUA way of doing this?

function MakeMovable(frame)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
end

now any other frames/buttons/w.e can be moved by just adding like the following code:

local frame = CreateFrame("Button", "UIPanelButtonTemplateTest", UIParent, "UIPanelButtonTemplate")
frame:SetHeight(20)
frame:SetWidth(100)
frame:SetText("Test Button")
frame:ClearAllPoints()
frame:SetPoint("CENTER", 0, 0)
MakeMovable(frame)

putting MakeMovable(frame) now makes the Button i just created Movable in the same manner as the one in XML, however the XML requires that i write it for each frame i create aswell as Register the Event, while this can just call the MakeMovable function.

Maybe i don't quiete get the language yet, or is there an even simpler way to implement moveframes?

Regards,
fRodzet
  Reply With Quote
03-19-13, 04:22 PM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
You just read the wrong guides
XML is not required and not used by many addons.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
03-19-13, 04:43 PM   #3
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
I don't use xml in any of my addons simply because I don't know anything about xml coding
__________________
Tweets YouTube Website
  Reply With Quote
03-19-13, 04:53 PM   #4
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
XML is a universal language that can be used in various applications and programming languages, whether to represent data or a graphical layout, like in WoW.

XML in WoW lua allows you to create templates for objects (frames etc), but you can use functions to get similar behaviour in lua. As far as I'm aware there is nothing you can do in XML that you can't replicate in lua (in this case). People who use XML to represent their GUI are often used to doing so in different environments. Habits tend to stick; it's not required to end a line with a semicolon in lua or wrap conditions in brackets, either, but Blizzard still does so in their own code.

TL;DR: Do what you want
  Reply With Quote
03-19-13, 05:37 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Errors in XML can be a lot harder figure out where as for the most part it's pretty straight forward with LUA errors.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
03-19-13, 06:01 PM   #6
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Allright, so if i'm reading the wrong guides.. which do you guys prefer?

Also all the AddOns that i looked at uses .XML for Graphics and minor Script Behaviours - DeadlyBossMods as for example. Ive read the wowprogramming.com book and just started at "Beginning Lua with World of Warcraft AddOns" - both instruct that you can use LUA for everything, but they also both recommend to learn XML as it somehow has some minor advantages in the Graphics section..

Anyways - i'd like a recommendation on where to start:

Should i just go trough wowpedia.org and try to learn it from there, or should i read another book or what do you suggest?
  Reply With Quote
03-19-13, 06:07 PM   #7
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
Best way to learn is to grab a simple addon, mess with parts of it and learn through trial and error how it works.

Or, that's how I did it.
__________________
Tweets YouTube Website
  Reply With Quote
03-19-13, 07:47 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
DeadlyBossMods is not a very good example. The addon works just fine, but the code is absolutely awful.

For some examples of addons with decent code and frames that don't use XML, take a look at BigWigs, Omen, Bartender4, TomTom, Mapster, or anything written by Haste or Tekkub. Both of those authors have a lot of small simple addons with clean code.

Also, many of the code examples on Wowpedia are *really* outdated, and were written many years ago when you actually needed to use XML for a lot of things because the Lua frame API was incomplete. Nowadays, the only thing you can't do without XML is create templates for inheritance by secure frames, but that's a pretty advanced topic and you can generally achieve your goal without using templates anyway. The actual API reference on Wowpedia is fine, though.

The only other reason you might use XML would be if you were already hooked on XML from some other realm of programming... though honestly I don't know any programmer who uses XML who wouldn't be ecstatic to never have to look at it ever again. It's great for readability for machines; not so much for humans.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 03-19-13 at 07:53 PM.
  Reply With Quote
03-20-13, 07:45 AM   #9
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Originally Posted by Phanx View Post
DeadlyBossMods is not a very good example. The addon works just fine, but the code is absolutely awful.

For some examples of addons with decent code and frames that don't use XML, take a look at BigWigs, Omen, Bartender4, TomTom, Mapster, or anything written by Haste or Tekkub. Both of those authors have a lot of small simple addons with clean code.

Also, many of the code examples on Wowpedia are *really* outdated, and were written many years ago when you actually needed to use XML for a lot of things because the Lua frame API was incomplete. Nowadays, the only thing you can't do without XML is create templates for inheritance by secure frames, but that's a pretty advanced topic and you can generally achieve your goal without using templates anyway. The actual API reference on Wowpedia is fine, though.

The only other reason you might use XML would be if you were already hooked on XML from some other realm of programming... though honestly I don't know any programmer who uses XML who wouldn't be ecstatic to never have to look at it ever again. It's great for readability for machines; not so much for humans.
Thank you for such a useful reply! I will look into those AddOns

I have a few other questions here:

Is it possible to write an Addon where you create a .Lua file simply for all the functions and then create other .Lua files to call these functions. Example:

A .Lua file named: MakeMovable.lua with the use of this code
function MakeMovable(frame)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
end

And then another .Lua file named e.g.: Button.lua and then call the function MakeMovable(frame) from the MakeMovable.lua file, like this

local frame = CreateFrame("Button", "UIPanelButtonTemplateTest", UIParent, "UIPanelButtonTemplate")
frame:SetHeight(20)
frame:SetWidth(100)
frame:SetText("Test Button")
frame:ClearAllPoints()
frame:SetPoint("CENTER", 0, 0)
MakeMovable(frame)

or do i have to keep these in the same file?
  Reply With Quote
03-20-13, 07:56 AM   #10
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
As an example:

Top of first .Lua file
Lua Code:
  1. local addon, ns = ...
  2. local Funs, Settings = unpack(select(2, ...))
  3.  
  4. Settings.defaults = {
  5.    x = 0,
  6.    y = 0,
  7. }
  8.  
  9. Funs.updateSettings = function()
  10.     -- do stuff
  11. end

Second file
Lua Code:
  1. local Funs, Settings = unpack(select(2, ...))
  2.  
  3. local Init = function()
  4.     Funs.updateSettings()
  5.     print(Settings.x, Settings.y)
  6. end

You can now access thingies from any file within your addon, as each file in your addon shares a hidden passed argument.
  Reply With Quote
03-20-13, 08:04 AM   #11
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Originally Posted by Nibelheim View Post
As an example:

Top of first .Lua file
Lua Code:
  1. local addon, ns = ...
  2. local Funs, Settings = unpack(select(2, ...))
  3.  
  4. Settings.defaults = {
  5.    x = 0,
  6.    y = 0,
  7. }
  8.  
  9. Funs.updateSettings = function()
  10.     -- do stuff
  11. end

Second file
Lua Code:
  1. local Funs, Settings = unpack(select(2, ...))
  2.  
  3. local Init = function()
  4.     Funs.updateSettings()
  5.     print(Settings.x, Settings.y)
  6. end

You can now access thingies from any file within your addon, as each file in your addon shares a hidden passed argument.
Ty!


Some links on where to start learning, which editors is good to use, maybe some books and other stuff would be very much appreciated! I am really in to learning this stuff, i find it very exciting!

Isn't there a very good guide out there guiding you trough every single step of creating a WoWAddOn? Like first learn you the basics of lua, then explains the control structures, etc?
  Reply With Quote
03-20-13, 08:56 AM   #12
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by fRodzet View Post
Ty!


Some links on where to start learning, which editors is good to use, maybe some books and other stuff would be very much appreciated! I am really in to learning this stuff, i find it very exciting!

Isn't there a very good guide out there guiding you trough every single step of creating a WoWAddOn? Like first learn you the basics of lua, then explains the control structures, etc?
Not that I've seen. There's the WoW Programming book, but I think it was written/updated back in WotLK. Their website is up to date, though.

For editors, I prefer Notepad++.

Last edited by Nibelheim : 03-20-13 at 09:00 AM.
  Reply With Quote
03-20-13, 09:20 AM   #13
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Some links on where to start learning, which editors is good to use, maybe some books and other stuff would be very much appreciated! I am really in to learning this stuff, i find it very exciting!

Isn't there a very good guide out there guiding you trough every single step of creating a WoWAddOn? Like first learn you the basics of lua, then explains the control structures, etc?
I wouldn't suggest a book. You'll accomplish a lot more by experimenting, and looking around the internet. I don't know if it is because I am part of a younger generation or what not, but books as references are losing their appeal. You can find exponentially more relevant information on the internet, faster; and as such, the learning process is less impeded by the frustration of looking through a book.

WoW Interface and WoWAce / Curse have very active communities with a lot of dedicated forums and sub-forums if you need help with a specific question, or want to try to find specific information. So long as you describe your questions adequately, ask clear questions, post your code, you'll find the help you need.

WoWwiki, WoWpedia, and WoWprogramming are going to be your best points of reference (at first). Each has articles on how to start an AddOn (.toc format etc).

Keep in mind that LUA is a language independent of WoW, and as such, you can find a LOT of information on general coding websites, or dedicated LUA websites.

Notepad++ is pretty cute.

Last edited by Clamsoda : 03-20-13 at 09:28 AM.
  Reply With Quote
03-20-13, 09:35 AM   #14
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Originally Posted by Clamsoda View Post
I wouldn't suggest a book. You'll accomplish a lot more by experimenting, and looking around the internet. I don't know if it is because I am part of a younger generation or what not, but books as references are losing their appeal. You can find exponentially more relevant information on the internet, faster; and as such, the learning process is less impeded by the frustration of looking through a book.

WoW Interface and WoWAce / Curse have very active communities with a lot of dedicated forums and sub-forums if you need help with a specific question, or want to try to find specific information. So long as you describe your questions adequately, ask clear questions, post your code, you'll find the help you need.

WoWwiki, WoWpedia, and WoWprogramming are going to be your best points of reference (at first). Each has articles on how to start an AddOn (.toc format etc).

Keep in mind that LUA is a language independent of WoW, and as such, you can find a LOT of information on general coding websites, or dedicated LUA websites.

Notepad++ is pretty cute.
Thanks for the Answer! I didn't know there was a difference between WoWWiki and WoWPedia? I thought they were one and the same.. Is both sites relevant or is one the better pick? I'm sorry for all the newbish questions but i really want to make my first useable addon, and i have the greatest idea in mind and it annoys the **** out of me that i can't accomplish it yet. I know it is possible because ived studied other AddOns and my idea is pretty much a mixture of those AddOns, all in one
  Reply With Quote
03-20-13, 10:03 AM   #15
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
WoWpedia is a bit more relevant than WoWwiki. I believe that WoWpedia was made, and is maintained by several people that moved on from WoWwiki(for whatever reason).
  Reply With Quote
03-20-13, 10:20 AM   #16
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
DeadlyBossMods is not a very good example. The addon works just fine, but the code is absolutely awful.

For some examples of addons with decent code and frames that don't use XML, take a look at BigWigs, Omen, Bartender4, TomTom, Mapster, or anything written by Haste or Tekkub. Both of those authors have a lot of small simple addons with clean code.

Also, many of the code examples on Wowpedia are *really* outdated, and were written many years ago when you actually needed to use XML for a lot of things because the Lua frame API was incomplete. Nowadays, the only thing you can't do without XML is create templates for inheritance by secure frames, but that's a pretty advanced topic and you can generally achieve your goal without using templates anyway. The actual API reference on Wowpedia is fine, though.

The only other reason you might use XML would be if you were already hooked on XML from some other realm of programming... though honestly I don't know any programmer who uses XML who wouldn't be ecstatic to never have to look at it ever again. It's great for readability for machines; not so much for humans.
I disaggre, there is a bunch of stuff which you can't make in lua or toc, but only in xml.
  Reply With Quote
03-20-13, 11:05 AM   #17
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Nibelheim View Post
As an example:

Top of first .Lua file
Lua Code:
  1. local addon, ns = ...
  2. local Funs, Settings = unpack(select(2, ...))
  3.  
  4. Settings.defaults = {
  5.    x = 0,
  6.    y = 0,
  7. }
  8.  
  9. Funs.updateSettings = function()
  10.     -- do stuff
  11. end

Second file
Lua Code:
  1. local Funs, Settings = unpack(select(2, ...))
  2.  
  3. local Init = function()
  4.     Funs.updateSettings()
  5.     print(Settings.x, Settings.y)
  6. end

You can now access thingies from any file within your addon, as each file in your addon shares a hidden passed argument.
From the code you posted, this starts an error propagating from the following line:
Code:
local Funs, Settings = unpack(select(2, ...))
This is because the shared addon table is empty and as such, both variables will be set to nil. Further code raises an attempt to index nil error.


Originally Posted by fRodzet View Post
Ty!


Some links on where to start learning, which editors is good to use, maybe some books and other stuff would be very much appreciated! I am really in to learning this stuff, i find it very exciting!

Isn't there a very good guide out there guiding you trough every single step of creating a WoWAddOn? Like first learn you the basics of lua, then explains the control structures, etc?
The websites mentioned are a good start. I've had experience with Lua prior to playing WoW at which I've learned from the documentation on Lua's official website. Note WoW uses Lua version 5.1 now. As far as books, as you've run into before, the WoW API is constantly evolving and books and guides will eventually become outdated as time passes.


Originally Posted by Clamsoda View Post
WoWpedia is a bit more relevant than WoWwiki. I believe that WoWpedia was made, and is maintained by several people that moved on from WoWwiki(for whatever reason).
WoWWiki started out being hosted independently and was fine at that point. The problem started when they moved to be hosted by Wikia.com. From then, Wikia.com forced the site to undergo drastic layout changes many people hated, including several admins. It was then the admins branched off and made WoWPedia, which is hosted by Curse.com.

I feel like an old geezer talking about this, "I've seen some things, man. And some stuff. I wouldn't recommend it."
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-20-13, 11:35 AM   #18
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Originally Posted by Resike View Post
I disaggre, there is a bunch of stuff which you can't make in lua or toc, but only in xml.
Like? There's one thing you can't do and it was already mentioned by Phanx.
  Reply With Quote
03-20-13, 12:28 PM   #19
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by SDPhantom View Post
From the code you posted, this starts an error propagating from the following line:
Code:
local Funs, Settings = unpack(select(2, ...))
This is because the shared addon table is empty and as such, both variables will be set to nil. Further code raises an attempt to index nil error.
Woops. Forgot a part. First file should be:
Lua Code:
  1. local addon, ns = ...
  2. ns[1] = {}
  3. ns[2] = {}
  4.  
  5. local Funs, Settings = unpack(select(2, ...))
  6.  
  7. Settings.defaults = {
  8.    x = 0,
  9.    y = 0,
  10. }
  11.  
  12. Funs.updateSettings = function()
  13.     -- do stuff
  14. end
  Reply With Quote
03-20-13, 12:49 PM   #20
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
One further lesson...

I'ts Lua, not LUA. Lua is Portuguese for "moon", not an acronym.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » H: Why XML and why LUA?

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