Lua & WML, when to use what?

Discussion of Lua and LuaWML support, development, and ideas.

Moderators: Forum Moderators, Developers

gfgtdf
Developer
Posts: 1110
Joined: February 10th, 2013, 2:25 pm

Re: Lua & WML, when to use what?

Post by gfgtdf » October 31st, 2018, 12:23 pm

Pentarctagon wrote:
October 30th, 2018, 11:49 pm
As far as performance goes, the large majority of the time I doubt this is a compelling reason to use one or the other. If you do end up needing the extra performance that lua can give, then of course use it, but unless you're doing something particularly complex it's unlikely anyone would notice a difference.
I have often enough seen addons that were noticabley slower than they could be, for example parts of Loti, WorlConquestII (the 1.12 version) and some other mp map on the 1.12 addonserver i currently dont rmember the name, and those were not even addons created by beginners, they were very well and structured written, and often even contained optimisations to increase performance (in wml). But were still in a slow compared to lua.
Pentarctagon wrote:
October 30th, 2018, 11:49 pm
Lua's stack traces are actually usually quite a bit more wordy than they really need to be, and I think would be rather intimidating to look at for people new to coding in general.
I again disagree here, unless it contains these 'wml stacktackes' becasue you used [lua] in [event] every single chracter of the erromessage is useful and makes it easier to spot the error, take for example this errormessage i got by adding a random typo in the in worldconquestII lua code Image i don't see a single chracter that i think is not helpful. Also note that what i said about wml errors wml desribed the _best_ case, often you get either no error message at all (happend often with typos), or totally cryptic stacktraces like
Spoiler:
Pentarctagon wrote:
October 30th, 2018, 11:49 pm

Using GUI2 dialogs in add-ons, which you can only invoke from lua(ironically), are much easier to for me to read when written as WML rather a giant lua table.
I disgree again, i don't think they are harder to read once you get used to it, and for reason 2.2 from my first post i'd always use lua tables over what celmin suggested the the post after yours.
enclave wrote:
October 31st, 2018, 7:52 am
Plus if there is anything that needs downloading u will potentially have problems with versions, where 1 player has some images, another player doesn't because they on different versions..
This is wrong, require_download does not only check it is instlled, it also checks that the versions match.

enclave wrote:
October 31st, 2018, 7:52 am
a single player campaign maybe.. for multiplayer I would still stick with WML, without any unit types, without any lua dofiles... etc.. because unfortunately, people still unlikely going to join a game where download is needed..
As in ravanna said in the post after yours, it is possible to get all the advatages of lua without requireing download, both of the addons that i maintain or wrote ('Pick your recruits' and 'World conquest II') do that in some way, in fact the sample erromessage above was from a 'nodownload' code.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

User avatar
Pentarctagon
Forum Administrator
Posts: 3623
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Lua & WML, when to use what?

Post by Pentarctagon » October 31st, 2018, 12:42 pm

gfgtdf wrote:
October 31st, 2018, 12:23 pm
Pentarctagon wrote:
October 30th, 2018, 11:49 pm
As far as performance goes, the large majority of the time I doubt this is a compelling reason to use one or the other. If you do end up needing the extra performance that lua can give, then of course use it, but unless you're doing something particularly complex it's unlikely anyone would notice a difference.
I have often enough seen addons that were noticabley slower than they could be, for example parts of Loti, WorlConquestII (the 1.12 version) and some other mp map on the 1.12 addonserver i currently dont rmember the name, and those were not even addons created by beginners, they were very well and structured written, and often even contained optimisations to increase performance (in wml). But were still in a slow compared to lua.
LotI and WC are definitely more complex than most add-ons though, I would say. That they in particular would benefit from using lua for performance reasons isn't really a huge surprise.
gfgtdf wrote:
October 31st, 2018, 12:23 pm
Pentarctagon wrote:
October 30th, 2018, 11:49 pm
Lua's stack traces are actually usually quite a bit more wordy than they really need to be, and I think would be rather intimidating to look at for people new to coding in general.
I again disagree here, unless it contains these 'wml stacktackes' becasue you used [lua] in [event] every single chracter of the erromessage is useful and makes it easier to spot the error, take for example this errormessage i got by adding a random typo in the in worldconquestII lua code Image i don't see a single chracter that i think is not helpful. Also note that what i said about wml errors wml desribed the _best_ case, often you get either no error message at all (happend often with typos), or totally cryptic stacktraces like
Spoiler:
I mean, your second screenshot is an example of exactly what I was talking about. That's a pretty terrible stacktrace, and essentially useless for determining anything other than "something broke". If that game_error message wasn't there, that second screenshot would have no useful information at all.

edit-
gfgtdf wrote:
October 31st, 2018, 12:23 pm
I disgree again, i don't think they are harder to read once you get used to it, and for reason 2.2 from my first post i'd always use lua tables over what celmin suggested the the post after yours.
I guess we'll have to agree to disagree then. Taking the show_dialog example from the wiki, if my options are:

Code: Select all

local helper = wesnoth.require "lua/helper.lua"
local T = helper.set_wml_tag_metatable {}
local _ = wesnoth.textdomain "wesnoth"

local dialog = {
  T.tooltip { id = "tooltip_large" },
  T.helptip { id = "tooltip_large" },
  T.grid { T.row {
    T.column { T.grid {
      T.row { T.column { horizontal_grow = true, T.listbox { id = "the_list",
        T.list_definition { T.row { T.column { horizontal_grow = true,
          T.toggle_panel { return_value = -1, T.grid { T.row {
            T.column { horizontal_alignment = "left", T.label { id = "the_label" } },
            T.column { T.image { id = "the_icon" } }
          } } }
        } } }
      } } },
      T.row { T.column { T.grid { T.row {
        T.column { T.button { id = "ok", label = _"OK" } },
        T.column { T.button { id = "cancel", label = _"Cancel" } }
      } } } }
    } },
    T.column { T.image { id = "the_image" } }
  } }
}
or

Code: Select all

[tooltip]
  id = "tooltip_large"
[/tooltip]
[helptip]
  id = "tooltip_large"
[/helptip]
[grid]
  [row]
    [column]
      [grid]
        [row]
          [column]
            horizontal_grow = true
            [listbox]
              id = "the_list"
              [list_definition]
                [row]
                  [column]
                    horizontal_grow = true
                    [toggle_panel]
                      return_value = -1
                      [grid]
                        [row]
                          [column]
                            horizontal_alignment = "left"
                            [label]
                              id = "the_label"
                            [/label]
                          [/column]
                          [column]
                            [image]
                              id = "the_icon"
                            [/image]
                          [/column]
                        [/row]
                      [/grid]
                    [/toggle_panel]
                  [/column]
                [/row]
              [/list_definition]
            [/listbox]
          [/column]
        [/row]
        [row]
          [column]
            [grid]
              [row]
                [column]
                  [button]
                    id = "ok"
                    label = _"OK"
                  [/button]
                [/column]
                [column]
                  [button]
                    id = "cancel"
                    label = _"Cancel"
                  [/button]
                [/column]
              [/row]
            [/grid]
          [/column]
        [/row]
      [/grid]
    [/column]
    [column]
      [image]
        id = "the_image"
      [/image]
    [/column]
  [/row]
[/grid]
I will choose the latter every time.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

gfgtdf
Developer
Posts: 1110
Joined: February 10th, 2013, 2:25 pm

Re: Lua & WML, when to use what?

Post by gfgtdf » October 31st, 2018, 12:57 pm

Pentarctagon wrote:
October 31st, 2018, 12:42 pm
our second screenshot is an example of exactly what I was talking about. That's a pretty terrible stacktrace, and essentially useless for determining anything other than "something broke". If that game_error message wasn't there, that second screenshot would have no useful information at all.
Yes but it's stacktrace of an wml error (wrong use of [unstore_unit] i think?, not sure i actualyl just copied it from the first page of the worldconquestII thread), you don't have these stacktraces when using only lua,
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

User avatar
Pentarctagon
Forum Administrator
Posts: 3623
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Lua & WML, when to use what?

Post by Pentarctagon » October 31st, 2018, 1:09 pm

gfgtdf wrote:
October 31st, 2018, 12:57 pm
Pentarctagon wrote:
October 31st, 2018, 12:42 pm
our second screenshot is an example of exactly what I was talking about. That's a pretty terrible stacktrace, and essentially useless for determining anything other than "something broke". If that game_error message wasn't there, that second screenshot would have no useful information at all.
Yes but it's stacktrace of an wml error (wrong use of [unstore_unit] i think?, not sure i actualyl just copied it from the first page of the worldconquestII thread), you don't have these stacktraces when using only lua,
It seems kind of strange that [unstore_unit] would give gibberish like the second screenshot, but wesnoth.wml_actions.unstore_unit would give something like the first screenshot, given the same data.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

Tad_Carlucci
Developer
Posts: 327
Joined: April 24th, 2016, 4:18 pm

Re: Lua & WML, when to use what?

Post by Tad_Carlucci » October 31st, 2018, 1:20 pm

There is more to "right choice" than expressiveness or speed.

Sometimes the right choice is governed by your successors. For example, if I write a campaign and expect others will maintain it because, let's face it, I'm old, even though Lua would clearly be the better choice, unless I have some compelling reason to choose Lua, I might be wiser to accept that most UMC authors know WML better and many don't know Lua at all.

Similarly, often, the "right choice" is governed by those around you. You may be the Gift of the Gods to Lua programming but if you're the only team member working on the project who understands Lua and everyone else on the team only knows WML (well, maybe some have a passing understanding of Lua) it would probably be wisest to go with WML.

Sometimes it comes down simply to inertia.
I forked real life and now I'm getting merge conflicts.

gfgtdf
Developer
Posts: 1110
Joined: February 10th, 2013, 2:25 pm

Re: Lua & WML, when to use what?

Post by gfgtdf » October 31st, 2018, 1:56 pm

Pentarctagon wrote:
October 31st, 2018, 1:09 pm
gfgtdf wrote:
October 31st, 2018, 12:57 pm
Pentarctagon wrote:
October 31st, 2018, 12:42 pm
our second screenshot is an example of exactly what I was talking about. That's a pretty terrible stacktrace, and essentially useless for determining anything other than "something broke". If that game_error message wasn't there, that second screenshot would have no useful information at all.
Yes but it's stacktrace of an wml error (wrong use of [unstore_unit] i think?, not sure i actualyl just copied it from the first page of the worldconquestII thread), you don't have these stacktraces when using only lua,
It seems kind of strange that [unstore_unit] would give gibberish like the second screenshot, but wesnoth.wml_actions.unstore_unit would give something like the first screenshot, given the same data.
Well first, these stacktraces are mostly related to all these wml loop constructs and event fireing, so yes even if you _would_ use that in lua it'd not give such bad stacktraces.

And second, you usually don't use wesnoth.wml_actions.unstore_unit in lua (as least not nearly as often as you would in wml), you use the lua functions like u:to_map() or u:extract() Writiung addons in lua doesn't mean porting a wml addon tag per tag to lua, you use lua ideoms, lua api etc. . So comparing wesnoth.wml_actions.unstore_unit to [unstore_unit] makes little sense.

Tad_Carlucci wrote:
October 31st, 2018, 1:20 pm
There is more to "right choice" than expressiveness or speed.

Sometimes the right choice is governed by your successors. For example, if I write a campaign and expect others will maintain it because, let's face it, I'm old, even though Lua would clearly be the better choice, unless I have some compelling reason to choose Lua, I might be wiser to accept that most UMC authors know WML better and many don't know Lua at all.

Similarly, often, the "right choice" is governed by those around you. You may be the Gift of the Gods to Lua programming but if you're the only team member working on the project who understands Lua and everyone else on the team only knows WML (well, maybe some have a passing understanding of Lua) it would probably be wisest to go with WML.

Sometimes it comes down simply to inertia.
Its true that addons written in wml might have a bigger chance to be maintained when you leave, but actually even in wml the chance is still rather small.

I'd alyways choose an much better developing for myself and a better experience for players, for a increased change to be maintained by someone else later.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

enclave
Posts: 909
Joined: December 15th, 2007, 8:52 am

Re: Lua & WML, when to use what?

Post by enclave » October 31st, 2018, 7:36 pm

gfgtdf wrote:
October 31st, 2018, 12:23 pm
As in ravanna said in the post after yours, it is possible to get all the advatages of lua without requireing download, both of the addons that i maintain or wrote ('Pick your recruits' and 'World conquest II') do that in some way, in fact the sample erromessage above was from a 'nodownload' code.
I'm quite sure that you are right, but my previous experiences were negative enough to risk my time and go experimenting into something that is not only doubting but also complicated, not well documented, and possibly not give me more than 10% advantage over just using [lua] tags..

Some time ago some guy approached me to optimize my add-on together by deeping it 100% into lua to increase the efficiency etc (it was really a badly written add-on, because it was my first one, it had many many folders with many many cfg inside them with all kind of mix of bad coding, bad macros and everything else, with one exception that it was actually working 100% bug free), he sounded like a prodigy coder (said he worked for intel etc), too smart for me (it's like comparing a 6 year old kid to a teacher..). I obviously told him that if he wants to do it he has to go solo, because after he do any changes I will never be able to figure out what is going on there as his level of lua was comparing to gfgtdf level and my level is like a noob kid, i told him that 6 months later he will disappear and I will never be able to continue maintaining my own add-on, plus i said that making it into lua will require download to join it (it was 1.12 so it had a huge influence, for me it's still huge on 1.14 too). Ok, he was actually full of enthusiasm and he went solo! And yeah it actually worked without need to download add-on, I was very impressed it was possible. But looking closer at his work, the add-on was full of bugs (well that's normal, not related to our topic), but replay server couldn't handle the add-on anymore, I couldn't watch replay from server (http://replays.wesnoth.org/1.14/), which means i can not read comments of players, watch games to figure out what needs changing/balancing/improving... replay server is like god-sent, it gives so much to a developer (who is actually interested in add-on from player point of view) and if it doesn't work it's very very very bad and I would prefer a super slow add-on that I can watch and some day optimize than a super fast add-on that I can't follow. The point is that I haven't seen so far a proof that pure lua can work 100% bug free without needing add-on to join... I believe you, but I haven't played the examples. And speaking about the guy, 6 months later he was gone without finishing add-on.. obviously. People can find New Settlers add-on in lua and in wml on add-on server 1.12 (there would be too much to change into lua for a normal human being, so it's still mostly in WML but works much much quicker, apart from tons of bugs, the guy wasn't much into debugging i think).
And i know that I don't want to even try it on existing add-ons of mine because I had seen the guy converting my add-on into lua.. even for a super coder like him it was not easy path.. many times he was happy with results, but I was reporting bugs to him, like - observers can not join game, gives error... replay server doesnt work for mod anymore.. etc. Y i believe you it's possible.. but no i don't actually...

gfgtdf
Developer
Posts: 1110
Joined: February 10th, 2013, 2:25 pm

Re: Lua & WML, when to use what?

Post by gfgtdf » October 31st, 2018, 8:19 pm

all of my add-ons use mostly lua including 'pick your recruits npt' and worldconquestII, the first is purely without download requirement and the second might actually also technically work without download. it's just marked as required download to make people download new versions quicker. You can just to to the mp server and obweve on of those there are always wc2 games (in order to observe these without installing it you need to do some workarounds for the reason mentioned above) , and most of the time you'll also find a 'pick your recruits npt' games if you need to see it by yourself.

I also took a quick look at the newsettlers lua code you mentioned , it seems well written for the most part (at leasat i didn't see anything bad then). It also contains some intersting stuff like reloading the engine during a game without game reloading. Something that immidiateley noticable though is that all oos preventions are disabled when the host uses debug mode. So if you got oos from that, then that might be one possible reason.

anyway, i think we are getttign too far away form the topic, i never intended to try to convince you to port your addons into lua, i just wanted to give my optinion in this thread, on when lua could/should be used in addons.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

enclave
Posts: 909
Joined: December 15th, 2007, 8:52 am

Re: Lua & WML, when to use what?

Post by enclave » November 1st, 2018, 3:02 pm

y me neither trying to convince anyone about anything :D nice to hear some comment about lua new settlers, it's quite interesting to receive opinion of expert in this subject.
I will have a look at pick recruits some day, will try to observe it from observe server etc.. if it's flawless bugwise then it might be worth for me to have a look at considering full lua soem day.. at least to learn something more advanced and possibly useful in life ;) if not wesnoth..
offtopic: observe server became better now, instead of saving often broken replay of replay, now it stores the savefile which works if u tick watch replay, its a huge advancement in my opinion.

i forgot to mention other great disadvantage of lua over WML in wesnoth. So back to the subject.. because lua was added later during wesnoth development it is much much less documented than WML. There are less examples of code, less topics in forum, less documentation overall... so if your main goal is to create an add-on and not to learn programming language I would go for WML first... and then switch to lua later...

by the way a tipical WML debug message is quite simple to understand:
wml debug message.jpg
it literarily does all the job for you, here it says that your macro from macros_advanced.cfg on line 1 has more arguments than what you are trying to put into it on line 135 of technologies_units.cfg (very simple... and easy)

one of other advantages is that this message happens before the game starts.. Unlike lua which will hit you when you don't expect it at all somewhere in the middle of the game. And then you screwed.

Yeah it's only one of examples... some other bugs may be hard to detect, but majority is simple..

User avatar
Celtic_Minstrel
Developer
Posts: 1275
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Lua & WML, when to use what?

Post by Celtic_Minstrel » November 2nd, 2018, 12:03 am

You get that error dialog for syntax errors or preprocessor errors, yeah; but for ActionWML logic errors, you get a Lua stack trace at best.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

Post Reply