date = "2022-01-12T00:23:27Z" title = "Lua in WebAssembly" description = "Lua has several interesting WebAssembly projects." tags = ["lua", "language", "webassembly"] template = "page_lang" [extra] author = "Fermyon Staff"
Lua is a lightweight scripting language designed to be easily embedded. It enjoys broad usage as a plugin-and-extension language, and has a large ecosystem. But it is not generally considered one of the top programming languages.
Lua does not have an official implementation of a Lua-to-Wasm compiler.
The following unofficial projects compile or run Lua in WebAssembly:
- Wasmoon runs Lua as a script in the browser via a Lua engine compiled to Wasm. It also works with Node.js and Deno, but does not appear to have WASI bindings.
- WebAssembly-Lua - Likely unmaintained emscripted-based compilation.
- Wasm_Lua is a project that compiles the Lua engine to WebAssembly, allowing you to run Lua as a script. It also appears to be unmaintained
It should also be possible to compile Lua interpreters written in Wasm-supported languages. For example, Hematita, written in Rust, should be compilable to Wasm. This is the same technique Bartholomew uses for Rhai scripting.
Wasmoon, the most promising of the above projects, is used to run Lua scripts (uncompiled) inside of browsers, Node, or Deno. The documentation describes usage.
No details.
Currently, there are no examples. None of the known implementations have WASI support.
Here are some great resources:
- This fun blog post explains how to tweak Lua to compile the interpreter to WebAssembly.
- Wasm2Lua is an interesting project that translates Wasm modules to Lua code.