Luau Web 1.1.0 @690 |
---|
Luau bindings with dynamic JavaScript interop for web browsers, Node.js, and TypeScript.
Luau Web [1.1.0@690] — Javascript bindings for Luau
This project uses luau-interop which is my fork of Luau with a rewritten WASM execution API.
Features
- Easy to use and you won’t have to call Luau C API functions yourself
- Create and override globals in the Luau runtime
- Luau can interact with all values from JS
- JS can interact with all values from Luau
- Embeddable in websites, and Node.JS without extra setup.
- Sandboxed environment, basically bulletproof
- Near-native performance (around 10% performance loss, still around 40M operations/sec, around the same as Luau’s demo Demo - Luau if not faster)
Security
The Luau runtime is safe and secure by design, and my fork preserves that safety.
The security is in your hands and you have to make sure the values and functions you expose to the runtime are also secure. You can follow the basic security principles in the wiki.
You could give the runtime access to a node library like fs
or any other, but only do it if you are only running your own trusted code, or if you heavily safeguard the exposed functions.
Risky Example
import FS from "fs";
import { LuauState, InternalLuauWasmModule } from "luau-web"
InternalLuauWasmModule.onRuntimeInitialized = () => {
const state = new LuauState({
FS
});
const func = state.loadstring(`print(FS.readdirSync('.'))`, "index.ts", true);
func();
};
For more info see luau-web/wiki/Security
Example Script
import { LuauState, InternalLuauWasmModule, LuauTable, LuauFunction } from "luau-web"
InternalLuauWasmModule.onRuntimeInitialized = () => {
const state = new LuauState({
example: function (str1: string, tbl: LuauTable, luaPrint: LuauFunction) {
luaPrint(tbl, "hi :3");
return str1 + tbl.one;
}
});
const func = state.loadstring(`print(example(..., {one = 2}, print)); return ...`, "index.ts", true); // prints "hello2"
console.log(func("hello")); // returns ["hello"]
};
It interacts and integrates cleanly with Luau values.
Limitations
- It should be pretty stable, but this is still new - report issues you encounter and I will fix them as best as I can.
- Some features, like full Luau value APIs, are still missing but will be added in a future update (most importantly buffer operations like
buffer.readu16
to be called on Luau value references)