Lua in the browser

The omnilua npm package runs Lua in a web page or in Node. You ship one wasm file and a small JS wrapper — no C interpreter to bundle, no native build.

Install and run

shell
$ npm install omnilua
js
import { loadLuaRs, luaRsWasmUrl } from "omnilua";

const { lua } = await loadLuaRs(luaRsWasmUrl, {
  onStdout: (chunk) => console.log(chunk),
});
lua.exec('print("hello from wasm")');

Pick a version, sandbox untrusted code

All five versions ship in the one wasm file; pass version when you load it. To run untrusted scripts, set limits before executing.

js
lua.setLimits({ maxInstructions: 5_000_000, maxMemory: 64 * 1024 * 1024, strict: true });
const r = lua.tryExec("while true do end");
console.log(r.ok, lua.lastTrip()); // false "instructions"
lua.sandboxReset();
Reference

Full wrapper API and Node usage: the npm package readme.

Next