WebAssembly scripting

4 replies [Last post]
Lyberta
Lyberta's picture
User offline. Last seen 16 weeks 4 days 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
Wuzzy's picture
User offline. Last seen 11 hours 55 min ago. Offline
Joined: 2012-06-20
Posts: 1084

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
nemo's picture
User offline. Last seen 18 hours 6 min ago. Offline
Joined: 2009-01-28
Posts: 1719

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

https://forums.civfanatics.com/threads/bobs-crappy-lua-math-library.521623/

perhaps

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

Wuzzy
Wuzzy's picture
User offline. Last seen 11 hours 55 min ago. Offline
Joined: 2012-06-20
Posts: 1084

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

Also:

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

EDIT:
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

nemo
nemo's picture
User offline. Last seen 18 hours 6 min ago. Offline
Joined: 2009-01-28
Posts: 1719

I wasn't aware of the integer divion operator. Was aware of the new type but didn't seem that useful due to automatic coercion.
Do they have integer equivalent for other math types?

As for square root, yeah, often it isn't needed, but it's hard to break people of the habit of not using it for distance. Even in the engine there were a few places.

I like that this new lua integer type is a full 64 bits too. I guess this really satisfies my main hedgewars lua annoyance.

Welp. One more reason to upgrade then.

WRT not many scripts using forbidden math, we *were* reviewing to catch it. There's also:
https://www.hedgewars.org/node/6961

I'm not sure what he ended up doing there.

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

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