Lua+XML = Easy Scriptable GUI?

Started by
5 comments, last by DantarionX 15 years, 4 months ago
I am trying to develop a Lua based GUI library on top of OpenGL. What I want to do is be able to write xml files that define the appearance layout of the GUI, with attributes that contain lua code to excute onClick, rollover, etc. It is feasible to use Lua+XML for this purpose? I want to do almost all of the logic in Lua, and only do the drawing of the gui elements in lua. For example, I could define how to draw gradients, images, boxes, borders, etc. In c++, and then use lua to implement buttons, sliders, menus, etc, by reusing those base components. The idea is that I can define a Menu in lua, create one in the XML file, and then have the C++ xml parser call lua code when it runs into the Menu component that it doesn't understand. A even better idea is to even do the XML parsing in Lua, leaving the drawing code in C++. The goal is to make as much as the system in Lua as possible, allowing me to port the GUI system to the Wii. The only parts I want to code in C++ are the system dependent parts, like init, texture loading, drawing, input, sound, etc. Is this a feasible idea? Can Lua do this? Are there any common problems I will have trying to implement a OO system in Lua? Should I use a C++ bind tool like luabind for this? Or is it best to code that myself? Any ideas guys?
~Dantar
Advertisement
I'm not sure why you're bringing XML into the equation. Lua was originally designed as a data description language, after all... why not define the GUI in Lua code instead?
Thats a wonderful question!

I will experiment with using just lua to create the GUI, but I think it will be easier to modify the position and nesting of GUI elements using XML. I really just want to use Lua to script the GUI elements so that they can do things onClick, onHover, etc.
~Dantar
Easy to modify positioning and nesting:
nameWindow = window {  x = 400,  y = 300,  color = GREY,  children = {    nameBox = textBox {      length = 15,      default = ""},    okButton = button {      text = "OK",      onClick = function() game.start() end    }  }}
The more I look at lua the more I like it!

The syntax really does let you do a lot of nifty things that would take hundreds of lines in c++. In fact, I think I will probably be able to support using xml+embedded lua to define layouts, and also allowing pure lua.

I still feel like for the purpose of nested widgets, xml gets the job done a bit clearer than defining parent/child relationships with code.

<Window name="nameWindow" x="400" y="300" color="GREY">
<TextBox length="15" defait=""/>
<Button text="OK" onclick="game.start()">
</Window>


Perhaps I will use a combination of the two forms, allowing constants and functions to be defined in lua code, and xml for the general creation of widgets
~Dantar
If I remember correctly, World of Warcraft uses Lua and XML for their GUI scripting. It might be worth checking out how they do it. You might even want to some WoW GUI modders to see what they like and don't like. Might help you improve your own design, both in what WoW did right and what they did wrong in the eyes of those who use the system...
Thanks visage!

I was actually talking to one of my friends who is a major WoW freak, and as soon as I mentioned Lua he said "isn't that the thing that WoW addons use?"

While I don't think my GUI elements will actually be that complicated, as I have no need for many text based components, I will take a look at how WoW's XML+Lua solution works.

I guess the people at blizzard were thinking the same way I am thinking now!
~Dantar

This topic is closed to new replies.

Advertisement