Page 1 of 1

WASM instead of Lua

Posted: Thu Oct 16, 2025 9:28 pm
by SSkeptix
Hi, I didn’t find a better place to ask this question.
I have a short technical question for the developers:
If you had to create the modding system again today, would you prefer to use WASM instead of Lua, or is Lua still the better choice for Factorio

Re: WASM instead of Lua

Posted: Sat Oct 18, 2025 12:59 am
by h.q.droid
Not a Factorio dev, but I won't consider WASM for a modding system:

- Bad development ergonomics. You have to compile something else into WASM, so it would be clunky to run something immediate from the map editor.
- Bad performance. WASM trades high interfacing overhead for computational efficiency. The evidence is WASM being much slower at DOM manipulation than vanilla Javascript. For a mod it's usually counter-productive since modding is mostly interfacing.

Do you have some computation-heavy modding ideas in mind? Maybe they can be implemented using some creative shader passes?

Re: WASM instead of Lua

Posted: Sat Oct 18, 2025 6:19 am
by SSkeptix
Thanks for the great answer! I hadn’t thought about the performance cost between the WASM and engine boundaries.
No, this question isn’t about any specific modding ideas — I’m a developer (but not a game dev). I'm just curious about how things work in the game development world or maybe I should say performance-optimized world.

Re: WASM instead of Lua

Posted: Sat Oct 18, 2025 12:49 pm
by Rseding91
I would be interested in trying C# as a modding language alternative, but I haven’t looked into the cons of it, and I’m unsure if it supports running on non-windows.

Re: WASM instead of Lua

Posted: Sat Oct 18, 2025 9:32 pm
by Tertius
Rimworld modding is C# based, however as far as I understand Rimworld itself is programmed in C# (Unity engine) and the modding "API" is just a hook into the class and object structure directly. It's directly patching the game, not going through a well defined modding api. A different concept than Factorio. And also as far as I know, mods are supported on all the platforms Rimworld is running on: Windows, Mac, Linux. Consoles are supported as well, but I don't know about mods for these.

Re: WASM instead of Lua

Posted: Wed Oct 22, 2025 5:52 am
by SSkeptix
I'm professional c# dev but not in game dev.
Nowadays, C# is very similar to Java — almost one-to-one. It’s cross-platform. Minecraft is written in Java and supports Java mods. The same goes for Vintage Story (a Minecraft clone): it’s written in C#, and you can write C# mods for it.

I see a problem with using Java and C# for mods — security. These mods can’t really be sandboxed, which means malicious actors could download the source code, add something harmful, and reupload it somewhere as a ZIP file.

That’s why I’m interested in WASM.

Re: WASM instead of Lua

Posted: Wed Oct 22, 2025 8:09 pm
by y.petremann
Tertius wrote: Sat Oct 18, 2025 9:32 pm Rimworld modding is C# based, however as far as I understand Rimworld itself is programmed in C# (Unity engine) and the modding "API" is just a hook into the class and object structure directly. It's directly patching the game, not going through a well defined modding api. A different concept than Factorio. And also as far as I know, mods are supported on all the platforms Rimworld is running on: Windows, Mac, Linux. Consoles are supported as well, but I don't know about mods for these.
One problem I see with C# for cross platform is that sometimes a mod dev decide to use a library that doesn't support all target OS and the the mod is broken, Space engineers (windows only) did something similar but they restricted the use of external and some standard library.
SSkeptix wrote: Wed Oct 22, 2025 5:52 am I'm professional c# dev but not in game dev.
Nowadays, C# is very similar to Java — almost one-to-one. It’s cross-platform. Minecraft is written in Java and supports Java mods. The same goes for Vintage Story (a Minecraft clone): it’s written in C#, and you can write C# mods for it.

I see a problem with using Java and C# for mods — security. These mods can’t really be sandboxed, which means malicious actors could download the source code, add something harmful, and reupload it somewhere as a ZIP file.

That’s why I’m interested in WASM.
The advantage of using lua is that there is no compilation on modder or player side, so players can download and see the code, but as factorio or space engineer did you gonna restrict some standard library and how other library are interconnected so they doesn't need to use external libraries.

You can also look about KubeJS which use a javascript engine (RhinoJS) for minecraft for peoples that don't want to have to compile things

In all case it's better that you game does the job of the compilation stuff or has a modding toolkit for that.

For the time I got in modding, I can say that factorio was for me the best experience I had, simply because I didn't have to install a modding environment that is two time the size of the game and that take 4 times more ressources than the game for working, debugging and compiling.

Re: WASM instead of Lua

Posted: Wed Oct 22, 2025 11:27 pm
by BrainGamer_
I can see WASM working well. Its already being used in a bunch of applications as a system to write extensions which are pretty similar to how mods work from a technical standpoint (ignoring the safety nightmare of mixin mods).

By using WIT and tooling like wit_bindgen DX would probably be even better than what we have now with LuaLS & FMTK which just does not work at all for slightly larger mods due to LuaLS just choking. Trying to tack on strong typing to a dynamic language is just not really doable unless you're microsoft.
h.q.droid wrote: Sat Oct 18, 2025 12:59 am Bad performance. WASM trades high interfacing overhead for computational efficiency. The evidence is WASM being much slower at DOM manipulation than vanilla Javascript. For a mod it's usually counter-productive since modding is mostly interfacing.
The only real interfacing overhead in the web with WASM is due to JS strings being UTF-16 while languages compiling to WASM usually want UTF-8 or ASCII.
But even that doesn't stop WASM based web frameworks from being as fast or even faster than JS based ones (https://www.youtube.com/watch?v=4KtotxNAwME).
And in the case of factorio modding that would be even less of a concern since both sides would use the same encoding for strings and the objects passed between the sides are usually not large anyways and instead are just a wrapped pointer / numeric identifier.
So performance should not be too bad either.