WebAssembly scripting

3 replies [Last post]
Lyberta's picture
User offline. Last seen 5 days 6 hours ago. Offline
Joined: 2016-09-10
Posts: 177

So, I can't stand Lua, it's a horrible mess that destroys your mental health and makes you suicidal.

Thankfully, there is an answer, no more need to embed specific language bindings, we can do better - WebAssembly (I know, the name is horrible). With WASM you don't have to force a specific language, you can use any language that can be compiled into WASM (which as of right now at least C, C++, Rust and maybe a lot of other languages I don't know of).

I'm pretty sure there will be (maybe already is) a way to compile Lua into WebAssembly so there would be a way to keep old scripts working. Looks like win-win.

Wuzzy's picture
User offline. Last seen 57 min 32 sec ago. Offline
Joined: 2012-06-20
Posts: 1039

I am strongly opposed to this suggestion. It's a major disruptive step with no clear benefit and it seems unrealistic anyway.

Changing the language would be a major commitment that is not going to happen overnight and IMO a big waste of time anyway. We would be busy to only change the language/system instead of being actually productive with fixing bugs, adding real features and missions.

Most importantly, I fail even to see any benefit from such a step even if we manage to pull off such a major change. Let's suppose we get that WebAssembly support, now what? Will it make new features possible that that were't possible before? Will it improve Hedgewars in the long run? Will it make development of scripts easier? I think the answer to all of these answers is a flat out “no”. The only change I see is increased complexity.

As for WebAssembly in particular: On first glance, this step seems very unrealistic anyway. It doesn't look like WebAssembly supports Lua yet, but I haven't looked closely. But even if, then what would be the point of having WebAssembly support in the first place? Replacing Lua would mean the loss of all existing scripts as well our Lua API documentation, everything has to be redone from scratch. Very bad idea. Then there's the teeny-tiny question on how to do WebAssembly from Pascal.

Frankly, just deal with Lua. Granted, Lua has its problems, I am fully aware of that, but it still gets it job done; there are languages far worse. NO language is 100% perfect. I am sick of discussions about how language XYZ is superior or inferior because they mostly revolve around details (only exception: PHP). Languages are just tools and a good programmer must know them.
Lua has been chosen as our scripting language a long time ago and it's not something we should change only because you don't like it. And Lua has served us well for years. I see no reason to replace it.

When I entered the Hedgewars development, I also had to learn some new langauges I didn't knew before, but I never complained about that, I just started learning and getting things done.

Hi, I am a Hedgewars developer. Smile I accept personal donations in bitcoin. Heart 17fsUywHxeMHKG41UFfu34F1rAxZcrVoqH

nemo's picture
User offline. Last seen 1 day 20 hours ago. Offline
Joined: 2009-01-28
Posts: 1683

I'd tend to agree... Lua is pretty well established in game scripting, I don't think there'd be any large advantage the ditching it in terms of the scripting community which is already fairly familiar with this from other games.

The only issue we have now that would make me sympathetic to this is that Lua's number type does not play nice with our deterministic lockstep at all. So we have these rules about only dividing by 2 or else using div(), not multiplying by anything but an integer, not multiplying too large, not using any trig (and we still haven't gotten around to exposing the engine trig, even though I did bring it up w/ Wuzzy in terms of things causing a problem with Lua that it'd be nice to have a helper table for), not using sqrt...

It's kind of a pain. Most of those would not be solved necessarily by web assembly, but there might be some nice fixed point / integer math libs out there in the non-lua world.. And at least other languages have actual integer types.

On the other hand, hm, wonder if anyone has ever written a fixed point math lib for lua already...



Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Wuzzy's picture
User offline. Last seen 57 min 32 sec ago. Offline
Joined: 2012-06-20
Posts: 1039

Lua 5.3 has introduced an integer data type (actually, a sub data type of number).

Literal numbers with no decimal point written out will be seen as integers in Lua. You can check the number type with math.type:

math.type(1) -- returns "integer"
math.type(1.0) -- returns "float"
math.type("hedgehog") -- returns nil

There's also a new integer division operator:

5//3 -- returns 1

Compare to the single slash division, which always gives a float:

5/3 -- returns 1.6666666666667


math.type(4//2) -- returns "integer"
math.type(4/2) -- returns "float"

About square root, there is a function called IntegerSqrt in Continental_supplies.lua, maybe we could move that one to the Utils Lua library.
Square roots are used only in 3 scripts anyway.

Hi, I am a Hedgewars developer. Smile I accept personal donations in bitcoin. Heart 17fsUywHxeMHKG41UFfu34F1rAxZcrVoqH

Copyright © 2004-2017 Hedgewars Project. All rights reserved. [ contact ]