Why not LUA?

Discussion among members of the development team.

Moderator: Forum Moderators

mihoshi
Posts: 52
Joined: February 16th, 2008, 10:18 pm

Re: Why not LUA?

Post by mihoshi »

Sapient wrote: Not an exhaustive list, but here's the first things that came to mind:

1) When reading the file later, you have to scan upwards to figure out which '}' matches the other (Keep in mind that some of our WML authors use Notepad or Wordpad, with no syntax highlighting). Once you unbalance the thing it can become a real mess to figure out where you went wrong.
Proper indenting helps. And there are free text editors that helps you with such matter - like SciTE.
Sapient wrote: If you look in our C++ files you will always find lines like this:

Code: Select all

} // end of namespace gui
There's a reason that comment is in there... and notice it is more verbose than "[/namespace]"
But is not used as often. And it saves from monstrocities like this piece in Survival Extreme:

Code: Select all


[/effect]

[/object]

[/then]

[/if]

[/command]

[/option]

            [/message]

           [redraw]

           [/redraw]

          [/do]

         [/while]

        [/command]

       [/option]
Sapient wrote: 2) All string literals have to be enclosed with appropriate quote marks
In Lua you can write something like flail = "flail" for all words with special meaning
in a header file. Also it's possible in Lua to default all unitialized variables to their names - see http://www.lua.org/manual/5.1/manual.html#2.8 and next paragraph. Or to report using of unitialisated variable as an error.

Code: Select all

3) Thus, there must be an escape syntax for special characters within strings
[/quote]

Lua deal with that beautifully as well. It has a special construction for quoting long strings -

[quote]
Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]. A long string starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. Literals in this bracketed form may run for several lines, do not interpret any escape sequences, and ignore long brackets of any other level. They may contain anything except a closing bracket of the proper level.
[/quote]

[quote="Sapient"]
4) very easy to forget a comma
[/quote]
Just as it's easy to make a typo in a closing tag.
User avatar
Noyga
Inactive Developer
Posts: 1790
Joined: September 26th, 2005, 5:56 pm
Location: France

Re: Why not LUA?

Post by Noyga »

mihoshi wrote:
Sapient wrote: Not an exhaustive list, but here's the first things that came to mind:

1) When reading the file later, you have to scan upwards to figure out which '}' matches the other (Keep in mind that some of our WML authors use Notepad or Wordpad, with no syntax highlighting). Once you unbalance the thing it can become a real mess to figure out where you went wrong.
Proper indenting helps. And there are free text editors that helps you with such matter - like SciTE.
That's not really something you can expect from a non programmer like our typical scenario writers.
"Ooh, man, my mage had a 30% chance to miss, but he still managed to hit! Awesome!" ;) -- xtifr
Jingo
Posts: 3
Joined: April 18th, 2008, 4:42 pm

Re: Why not LUA?

Post by Jingo »

Hi,

Sorry to write an IMHO post here even if you don't know me.
Just a little presentation.
I worked on few commercial games for Gamecube/PS2/PSP/Xbox360. I'd like to give the names but I don't know if I can because of the technology related stuff I'll explain.

In my company, we had a home-made script that was really shity. (damn WML is a lot better ;) ).
But for my last two projects, we needed something better more extended and we used LUA.

Our problems were the same than yours:
- We could extend our own script engine (adding conditional branching, etc ..)
- Our designers were not used with programming before (even doing a script of 10 lines was sometimes complicated for them or just because they didn't like to "code")
- Plus as a commercial project we always have to evaluate risk to take a new technology like LUA.

Finally, we implemented LUA. It was really easy.
And we were really surprised to see our designers enjoyed to code with it and they did a gameplay flow really more complicated than we expected. And it saved a looot of times for designers (actually I don't know if we could have been able to ship the game in times without LUA).

I'd like to answer to some worries I read in this thread:
- "LUA is much better then WML" That's not necessarily true. The advantage of LUA are: simple, easy to implement and extendable. But when you have a crash in LUA core code (C code) well good luck to understand anything ! For example where you messed up the LUA stack in your C/C++ code (not possible in LUA code).
- "The WML syntax is so easy that you probably can learn it in one day if you're familiar with other scripting languages" Well actually you can learn it but how many scripters already knows LUA. A lot of people already code in LUA. For example you can see what people did by scripting their own GUI on Wow with LUA.
- Why not trying to extend WML ? Because what you want LUA already did it. So why keep trying to spend time on WML when you can save it (and I'll tell you you'll save time) with LUa and a new feature like a new setting in a cfg can be done just by adding a C function (how much time does it take to do it with the WML engine ?)
- "removing something that works right now and replacing it with some vague idea, that's not a good move" Yes you're right. But a good thing is to see in the future. A lot of tasks (even a SoC idea) is about refactoring / extending the WML language. So why not trying another solution which can give so much more features really easily ?
- "but going in this direction why not give people direct C++ input" Because you'd never expect scripts/designers to code in C /C ++ because to be honest it's a real plain in the ass, dealing with pointers, etc ... (but intersting point, the UnrealScript are really close to C++)
- "If a non-coder was trying to understand this LUA he might ask what does two equals signs next to each other mean?" Yes actually he doesn't really care. He knows the == is to test equality and he's happy with it. I saw some non-coders work with LUA and they didn't ask us question like that, because wel ... they don't care ;)
- "WML is better for storing wesnoth-related data" Actually, LUa has been used a lot fo times just to store data. The way do it is simple. For WML you can convert each tag in LUA by a function coded in C.

I really like Wesnoth. It is a really good game and I'd like to see more extendabilty by a real scripting engine for campaigns and scenarios.
I'd like to try to do a LUA implementation in Wesnoth soon. We'll see the result. But actually having WML/Python and now LUA is not such a good idea because it means supporting three languages and implementation. Tt's always better to support just one thing and stick with it. (maintain cost/times, etcc ...)
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Why not LUA?

Post by Sapient »

Jingo wrote:"The WML syntax is so easy that you probably can learn it in one day if you're familiar with other scripting languages" Well actually you can learn it but how many scripters already knows LUA. A lot of people already code in LUA. For example you can see what people did by scripting their own GUI on Wow with LUA.
There's an important difference between Wesnoth and WoW... Wesnoth is open source and collaborative. If you want to extend the GUI in a significant way, you don't have to use an advanced scripting language. You can write it in C++ by re-using and improving our existing GUI code, and then submit a patch that improves the game for everyone. And it would probably take parameters via WML that allow some very simple custimization accessible to many people. That would probably be a lot easier than hacking something together in LUA. Certainly, it would be easier for me.


I still have yet to see tangible proof of all this work that LUA is allegedly going to save us.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
turin
Lord of the East
Posts: 11662
Joined: January 11th, 2004, 7:17 pm
Location: Texas
Contact:

Re: Why not LUA?

Post by turin »

Incidentally, in the unlikely circumstance that we did decide to switch to Lua, how easy would it be to convert all the WML files to Lua files?...
For I am Turin Turambar - Master of Doom, by doom mastered. On permanent Wesbreak. Will not respond to private messages. Sorry!
And I hate stupid people.
The World of Orbivm
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Why not LUA?

Post by Sapient »

turin -- I think a fully functional WML -> LUA converter would be one of the requirements for us to even seriously consider it. If LUA is so much more powerful as people claim, then I'm sure that will be an easy task for them. :)
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Jingo
Posts: 3
Joined: April 18th, 2008, 4:42 pm

Re: Why not LUA?

Post by Jingo »

A converter won't be such a problem to do I think.
If you want to extend the GUI in a significant way, you don't have to use an advanced scripting language. You can write it in C++
Yeah but they could have done it in WoW by a DLL But it's like asking to people to code their scenarios of Wesnoth in C++ ;)
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Why not LUA?

Post by Sapient »

name=scenario
not_equals= "GUI mod"

The current model is:
-simple tasks (such as typical scenarios) are done in WML
-very complex tasks (such as GUI mods) are done in C++
-if WML needs to do something very complex it can be arranged by
a) writing the new code that does the task in C++
b) new [tag] that invokes the behavior and is as simple as possible for ALL to understand
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Re: Why not LUA?

Post by Dave »

turin wrote:Incidentally, in the unlikely circumstance that we did decide to switch to Lua, how easy would it be to convert all the WML files to Lua files?...
I don't think we would ever "switch" to Lua.

What I think is suggested would be to add Lua as a new language that is used, so some 'moderately complex' functionality is carried out in Lua. Simple things would still be done in WML, complex things in C++, but things 'in between' could be done in Lua.

Removing WML altogether and using Lua completely for everything would be a total non-starter. As much or moreso than if someone suggested we re-write Wesnoth in Java.

David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
Jingo
Posts: 3
Joined: April 18th, 2008, 4:42 pm

Re: Why not LUA?

Post by Jingo »

Ok I'm cool with it.

Anyway I just wanted to give you my experience with LUA and switching from another scripting engine. That's all ;)
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Why not LUA?

Post by Sapient »

In the spirit of open discussion, I'm not going to lock this thread (yet). But I will ask anyone who posts here to read the entire discussion and make sure you are genuinely contributing something new to the discussion and/or actually have something useful to offer more than talking up LUA ("LUA is great, blah blah blah").


:annoyed:

This is known as a "soft lock"
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Re: Why not LUA?

Post by Viliam »

Jingo wrote:I'd like to try to do a LUA implementation in Wesnoth soon.
I suggest you take one mainline scenario and fully rewrite it in Lua. Do not forget localization, do not forget variable expansion in strings,...

If you switch to another language, you not only change the syntax, but also must make new objects in the new language. Like there is a difference between saying "why not write web pages in XML?" and "here is the XHTML 1.0 specification", there is also a big difference between saying "why not write Wesnoth data in Lua?" and "here is the how exactly you can do everything in Lua".

Currently, WML files contain data. Some of these data are "code" which will later be "run", when the C++ code decides it is the right time. (I am speaking about events.) IMHO analogic Lua code would create objects, and some of these objects would have functions as properties, and those functions would be called from C++ code when necessary. I think it would look a bit differently from a typical Lua project. But this way it would require less rewriting of C++ code. -- Maybe I am completely wrong here. But things like this must be discussed and solved (at least temporarily) before any serious change can begin.
User avatar
Geos
Posts: 115
Joined: March 20th, 2008, 1:58 pm
Location: Italy

Re: Why not LUA?

Post by Geos »

Very interesting topic.
I see that several people here believe a tag language like WML would be always more simple for the user than something more... programming like.
Well, the first source code I ever did or saw was HTML. Right now I still find it very difficult to work with. C++, fantastic, so easy... It's true.
Only developers of Wesnoth can decide if it is worthy to support another language but I work as a developer, and have always study by myself. I always found easier programming languages, even if they are more abstract, or maybe because of that.
I believe we shouldn't think a non programmer will not be able to learn some basic programming. Come on, we are not talking about delegates here, just a little bit of basic operators (we forget about Xor, ok), members and functions and a little bit of arithmetic.
I think it's very easy for a non programmer, and WML get very complex when a little bit of programming is needed.
That's ridiculous, dragons have no windows...
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Why not LUA?

Post by Sapient »

Geos wrote:Very interesting topic.
I see that several people here believe a tag language like WML would be always more simple for the user than something more... programming like.
Take away the word "always", then replace it with "when designing simple Wesnoth scenarios." No one here is claiming that WML is always simpler than LUA for all situations, and I think you obviously didn't read the entire thread as I asked before posting.
Geos wrote:Well, the first source code I ever did or saw was HTML. Right now I still find it very difficult to work with. C++, fantastic, so easy... It's true.
So now you're claiming that it's easier to write code in C++ than to construct a webpage with HTML elements? That's a surprising statement. I'd really be curious what kind of programs you've managed to produce if you can't really grasp HTML.
Geos wrote:I work as a developer, and have always study by myself. I always found easier programming languages, even if they are more abstract, or maybe because of that.
I believe we shouldn't think a non programmer will not be able to learn some basic programming.
I believe we shouldn't think a developer/programmer like yourself will not be able to learn some basic WML programming.

Geos wrote:Come on, we are not talking about delegates here, just a little bit of basic operators (we forget about Xor, ok), members and functions and a little bit of arithmetic.
I think it's very easy for a non programmer, and WML get very complex when a little bit of programming is needed.
Ok, so when was the last time you needed Bitwise-Xor or Functions, or Arithmetic beyond simple addition/subtraction to construct your wesnoth scenario? Note: we are planning to add function support to WML but I doubt that many people will really use it. "Members" already exist (e.g. $container.member).

Here you are claiming that you are a self-taught developer and C++ is easy for you... then expecting us to make WML conform to your desires so it will be easier for you to understand it. Meanwhile, turin, a self-proclaimed non-programmer, is easily answering your questions in the WML Workshop.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Geos
Posts: 115
Joined: March 20th, 2008, 1:58 pm
Location: Italy

Re: Why not LUA?

Post by Geos »

Ok, no need to get mad.
My point was just that programming, specially something basic, doesn't need to be hard. I was talking about examples like the one I read (in this thread) where some users would doubt that a non programmer could be able to understand this

Code: Select all

if x== 1 then
x=2
end
Or it has been said that Functions would be though to understand. Well, if they can understand Macros, functions are just one step over, under my point of view.

I was confirming the point, exposed in this thread once again, that WML is, as HTML, good to store data, but gets a little complex when you actually want to DO things, like the case of a scenario. Would not be needed for Unit, for example (as it has been said in this thread).

So, if you leave a thread open for people to express their opinions, expect them to happen. I did not write a "LUA is so cool" post, as you asked for. I just doubted that a non programmer can not understand basic programming.

As I said, only developers of Wesnoth can decide if it is worthy to implement that support, but my opinion is:
It would be cool to have some scripting, the same way HTML does support some.

And, by the way.
Meanwhile, turin, a self-proclaimed non-programmer, is easily answering your questions in the WML Workshop.
What was that? Comments like this I believe do not encourage participation. I am new in WML, so yes, I have questions. If you want, lock the thread, it is your right, but I don't see the point in getting offensive, I don't believe I was.
And, just in case it wasn't clear, I believe WML is a pretty impressive good work, but why closing the door to debate about how could it get better?
That's ridiculous, dragons have no windows...
Post Reply