Lua in WebAssembly

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.

Available Implementations

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.

Usage

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.

Pros and Cons

No details.

Example

Currently, there are no examples. None of the known implementations have WASI support.

Learn More

Resources:

  • Wasm2Lua is an interesting project that translates Wasm modules to Lua code.