View Single Post
01-16-11, 04:18 AM   #18
Cladhaire
Salad!
 
Cladhaire's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 1,935
Originally Posted by Xinhuan View Post
There are reasons why making frames in Lua is preferred over doing it in XML.
For some people, yes. People make it sound like a universal and that is just not the case. A mixture of XML and Lua should almost always be used in order to make the best use of the UI subsystem.

1. Error checking is easier. If the XML file contains a syntax error, WoW doesn't tell you which line it is on. You have to use an XML parser (such as opening the XML file in Internet Explorer) which will then tell you what line gave an error. The Lua interpreter doesn't give an error unless there is code that expects a frame to be present.
Except XML files can be validated, which is even more than checking syntax. It can tell you if you don't have things structured properly, if you're supplied attributes that don't apply to a frame. That's no different than having to 'run' the addon to see if your Lua code works, and gives you much more feedback.

2. Creating frames in Lua is far less verbose. It is less lines of text and fits on a page of text easily rather than 3 times the amount of lines. Less chances of mistakes is good.
Until you have to make templates, in which case Lua gets more verbose than XML, or you have to wrap things in factory functions which may or may not work.

3. Frames in XML are always created (excluding templates). Frames in Lua have the opportunity to be created only when needed on demand.
This is also a good thing, because the definition of the frame and its sub-components are atomic and are always created correctly. I would wager that a large percentage of frame-level problems that exist are because frames are created (improperly) in Lua.

4. For code in Lua to access a frame or texture created in XML easily, you need to name the frame/texture (which adds it to _G). Although this is circumventable with a bit of tricks, if the frame/texture is simply created in Lua and assigned to local variables or table subentries, we wouldn't have this problem.
There are no tricks. There has been an attribute for this since late 3.x. You can assign a sub-frame to have a key set in the parent table. Certainly you'll have to look up the first frame, but why is that a problem?

I'm not saying XML is always the answer.. but people avoiding it completely are doing themselves a disservice.

1. If your frame needs to have a name (or should have a name), which is most, then it should have a name. If you're doing this in Lua or XML it doesn't matter and the 'lookup' argument fails.

2. If your frame needs to be created when the addon is loaded, why does it matter that you can create them dynamically using Lua? Why NOT create your main frame in XML if you so desire?

People who sit here and evangelize their hate of XML without espousing any of its benefits to newer members of the addon community do absolutely everyone a disservice.
__________________
"There's only one thing that I know how to do well and I've often been told that you only can do what you know how to do well, and that's be you-- be what you're like-- be like yourself. And so I'm having a wonderful time, but I'd rather be whistling in the dark..."
  Reply With Quote