Instantiates the lu5 WebAssembly instance
- [path]
string
WebAssembly binary path, by default, the official lu5 cdn is used to servelu5.wasm
A promise which passes a lu5 instance.
lu5.init()
.then(vm => console.log(vm))
With another lu5.wasm
build
lu5.init('/path/to/my/build/lu5.wasm')
.then(vm => console.log(vm))
Compiles the WebAssembly Module for later use.
- [path]
string
WebAssembly binary path, by default, the official lu5 cdn is used to servelu5.wasm
A promise which passes the WebAssembly Module
lu5.compile('path/to/my/lu5.wasm')
.then(module => console.log(module))
Instantiates the lu5 WebAssembly instance
- module WebAssembly module, previously loaded with
lu5.compile
A promise which passes a lu5 instance.
You need to compile first
const module = await lu5.compile('path/to/my/lu5.wasm')
lu5.instantiate(module)
.then(vm => vm.execute('print("Hello from lu5")'))
Evaluate and run a lua script string.
- code
string
The lua script string
- A promise which passes a lu5 instance
lu5.init()
.then(vm => vm.execute('print("Hello from lu5!");'))
.then(vm => vm.execute('print("Hello again!");'))
Clear the lua state
None
- A promise which passes a lu5 instance
lu5.init()
.then(vm => vm.execute('x = 42'))
.then(vm => vm.execute('print(x)')) // 42
.then(vm => vm.reset())
.then(vm => vm.execute('print(x)')) // nil
Set the canvas id
- [id]
string
The canvas id
- A promise which passes a lu5 instance
lu5.init()
.then(vm => vm.setCanvas('mycanvas'))
.then(vm => vm.execute(`
function setup()
createWindow(200, 200);
end
function draw()
background('orange');
circle(100, 100, 50);
end
`))