A WebAssembly instantiator & Javascript polyfill for lu5 in the browser
npm install lu5-wasmA minimal WebAssembly instantiator & javascript polyfill for the lu5 interpreter.
* No async
* No file i/o
* No matrix transform stack (translate, rotate, scale)
* No 3D Rendering
* No setjmp & longjmps
* No exception handling (we currently use a workaround)
Add the lu5-wasm library from a CDN
``html`
Add a script
`xml`
Out of the box, lu5-wasm will search for and execute lu5 scripts in the document.
Add a canvas with an id
The canvas can be placed anywhere in your document's body
`html`
Include a lu5 script with a canvas attribute referencing the canvas id
`html`
as a libraryFor more specialized use cases, you may prefer to use lu5-wasm in library mode.
This will disable the auto-execution of lua scripts in your document.
Add the lib attribute to the script tag to enable library mode
`html`
Instantiate lu5 with the wasm binary and execute scripts.
`jsprint('Hello from lu5!')
lu5.init()
.then(vm => vm.execute())
.then(vm => vm.execute(
function setup()
createWindow(400, 400);
end
function draw()
background('green');
end
));`
You can use the state from previous execute calls
`js`
lu5.init()
.then(vm => vm.execute('x = 12'))
.then(vm => vm.execute('y = 18'))
.then(vm => vm.execute('print(x + y)'));
Call lu5.reset to clear state
`js``
lu5.init()
.then(vm => vm.execute('x = 12'))
.then(vm => vm.reset())
.then(vm => vm.execute('print(x)')); // nil
See DOCUMENTATION.md.