A 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
<script src="https://unpkg.com/lu5-wasm@latest/dist/lu5-wasm.min.js"></script>
Add a script
<script type="text/lua">
function setup()
createWindow(400, 400);
end
function draw()
background('magenta');
end
</script>
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
<canvas id="game"></canvas>
Include a lu5 script with a canvas
attribute referencing the canvas id
<script type="text/lua" src="sketch.lua" canvas="game"></script>
For more specialized use cases, you may prefer to use lu5-wasm
as an ES Module.
This will disable the auto-execution of lua scripts in your document and export api functionality.
Use the lu5-wasm-lib.min.js
bundle
<script type="module" src="https://unpkg.com/lu5-wasm@latest/dist/lu5-wasm-lib.min.js"></script>
Instantiate lu5
with the wasm binary and execute scripts.
lu5.init()
.then(vm => vm.execute(`print('Hello from lu5!')`))
.then(vm => vm.execute(`
function setup()
createWindow(400, 400);
end
function draw()
background('purple');
end
`));
You can use the state from previous execute calls
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
lu5.init()
.then(vm => vm.execute('x = 12'))
.then(vm => vm.reset())
.then(vm => vm.execute('print(x)')); // nil
See DOCUMENTATION.md.