r/lua • u/rohitwtbs • May 03 '25
Discussion Is lua a good choice for making webassembly games instead of rust?
I am trying to make web games in webassembly. have tried rust bit the learning curve for rust is too much . will lua be a good choice to make webassembly games?
11
Upvotes
7
u/Zireael07 May 03 '25
AFAICT Lua can't be compiled to webassembly in practice (all I've seen is horrendously outdated and/or just a REPL which means you can't make a game with it)
If Rust is too much (been there done that) you could try MoonBit?
5
u/SkyyySi May 03 '25
Nope. Web assembly works best with languages that are statically typed, AOT compiled and runtime-free. If you want to use Lua in the browser, you have to ship an interpreter with it, which then runs on top of another interpreter provided by your browser. While this is absolutely doable, it will be a hassle to set up, in addition to being very inefficient (though most certainly still enough for simple 2D games).
If you want a fast scripting langauge that feels similar to Lua, while also being easily usable everywhere: Consider using JavaScript.
3
u/MrHanoixan May 03 '25
Pros:
* Lua is one of the easiest languages to learn
* The Defold game engine exports to webassembly and uses Lua. Cocos2D and Love (via love.js)) also support HTML5, but I'm not sure on webassembly specifically.
Cons:
* In these engines Lua is interpreted for webassembly, not compiled (or jitted with LuaJIT), so it will be slower than Rust, but nowhere near unusable for simple to moderate complexity games.
I don't know what type of game you're making, so I can't really offer an opinion on whether the above engines are appropriate. And to be honest, even though I love Lua, I'd base my decision on the engine, not just the language. Also, what kind of community support you get really depends on the engine, not so much the language, when the language is simple.
For example, Godot out of the box is IMO much easier to use than Defold, and has a bigger community. Its primary language (GDScript) is simple, and feels a bit like Python. That's the direction I'd go if I was a relative beginner.
2
u/boruok May 03 '25
sounds like you searching defold engine.
2
u/[deleted] May 03 '25
https://github.com/Doridian/LuaJS
2
u/The-Malix May 03 '25
You could also consider Godot / Redot I think
I don't remember if they're able to target WASM
2
u/McHoff May 13 '25
Use Lyte2d! It's great and trivial to publish wasm builds.
1
u/bidaowallet May 07 '25
yes it is, Lua fully support WebAssembly and vice versa