- Joined
- Jun 13, 2016
- Messages
- 580
so we all love using anything except Lua itself to make maps these days, hence the absolute zoo of transpilers targeting JASS, vJASS, TypeScript, C#, Python, whatever
i just realized we can add one more language to this list (actually far more than one, more on that later): Rust
Rust can easily compile into WASM via the wasm32-unknown-unknown target, and being a Rust shill i can go on forever about how great it is.
there's also at least two tools for transpiling WASM into Lua: wasm2lua and Wasynth. the former uses node, the latter is written in Rust itself, so Wasynth is of more interest to me as a portable runtimeless solution
that means we can do Rust -> WASM -> Lua
admittedly the generated Lua code is quite shite, mainly because it has to emulate WASM's linear memory, so it'll probably run like ass, but hey, who cares, its not like we're trying to solve a massive performance problem here, most WC3 logic is just a bunch of function calls and some collection management
other than that all we need is a bunch of simple shims on the Lua side and a supporting lib for Rust that'll use those shims and we should be good to go.
im now lowkey considering doing a POC map in Rust. i know y'all nerds probably couldn't care less for Rust, but hey, whatever, this is fun
...
yeah okay this isn't just limited to Rust either, we could in fact use any language that has WASM as a compilation target. like AssemblyScript, im just bringing up Rust because it would be an insanely powerful language to bring into the fold
pros and cons:
i just realized we can add one more language to this list (actually far more than one, more on that later): Rust
Rust can easily compile into WASM via the wasm32-unknown-unknown target, and being a Rust shill i can go on forever about how great it is.
there's also at least two tools for transpiling WASM into Lua: wasm2lua and Wasynth. the former uses node, the latter is written in Rust itself, so Wasynth is of more interest to me as a portable runtimeless solution
that means we can do Rust -> WASM -> Lua
admittedly the generated Lua code is quite shite, mainly because it has to emulate WASM's linear memory, so it'll probably run like ass, but hey, who cares, its not like we're trying to solve a massive performance problem here, most WC3 logic is just a bunch of function calls and some collection management
other than that all we need is a bunch of simple shims on the Lua side and a supporting lib for Rust that'll use those shims and we should be good to go.
im now lowkey considering doing a POC map in Rust. i know y'all nerds probably couldn't care less for Rust, but hey, whatever, this is fun
...
yeah okay this isn't just limited to Rust either, we could in fact use any language that has WASM as a compilation target. like AssemblyScript, im just bringing up Rust because it would be an insanely powerful language to bring into the fold
pros and cons:
- + pro: using linear memory for storage means we put much less pressure on the GC and can avoid weird GC leak scenarios
- - con: using linear memory means a lot of weird bit twiddling and working with integers which lua can be a bit tricky with. also the current codegen in Wasynth emulates integers in software, yikes. 32-bit int types (and smaller) can probably use lua's builtin number type tho with some tweaks to the codegen, because it still has 53 bits of integer precision when the exponent is set to 0
- + pro: Rust has one of the most powerful type systems among modern languages
- - con: the codegen relies a lot on table lookups and helper functions to do anything
- - con: needs extra scaffolding (and maybe a fork of the codegen) to actually be useful in WC3
- + pro: can use almost any no-std crate in the Rust ecosystem for shit like math, crypto, memes, utility. dont need to reinvent the bicycle
- + pro: massive meme