Jump to content

View more

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Lua+XML = Easy Scriptable GUI?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 DantarionX   Members   

166
Like
0Likes
Like

Posted 25 November 2008 - 07:34 AM

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?

#2 Sneftel   Senior Moderators   

1788
Like
0Likes
Like

Posted 25 November 2008 - 07:37 AM

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?

#3 DantarionX   Members   

166
Like
0Likes
Like

Posted 25 November 2008 - 07:46 AM

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.

#4 Sneftel   Senior Moderators   

1788
Like
0Likes
Like

Posted 25 November 2008 - 11:54 PM

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
}
}
}


#5 DantarionX   Members   

166
Like
0Likes
Like

Posted 26 November 2008 - 06:44 AM

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

#6 choffstein   Members   

1090
Like
0Likes
Like

Posted 26 November 2008 - 07:33 AM

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...

#7 DantarionX   Members   

166
Like
0Likes
Like

Posted 26 November 2008 - 07:49 AM

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!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.