Project to demo executing lua code that dynamically loads a dynamically loads a shared library (lua-cjson) in the browser using WebAssembly.
- When play button is clicked, the lua script is passed to
lua_interop
lua_interop
will userunner.lua
to execute the scriptrunner.lua
will wrap the script's return value in a "result" table, serialise it JSON using the lua-cjson library and then return it back tolua_interop
lua_interop
will pass the result back to the webpage- The webpage will parse the JSON and display the result on the screen with green-ish/red-ish highlighting based on the result status
Using the cjson library in the lua code dynamically loads it at runtime. To get this to work in WASM, it needs to be compiled as a SIDE_MODULE
.
- Compile
lua
as a WASM side module - Compile
lua-cjson
into a WASM side module & rename atrifact tocjson.so
to allow the lua runtime to dynamically load it at runtime - Compile
lua-interop.c
into a WASM main module
- bash on linux-like environment (for Windows use WSL2)
- Docker
- Docker Compose
- An
.editorconfig
compliant editor
Main project commands:
./bin/build
- builds the project./bin/run
- runs the project. Webpage accessible on port8080
./bin/shell
- shells into the development environment./bin/clean
- deletes compiled artifacts
To run the project: ./bin/build && ./bin/run
When running commands under ./bin/
a new ephemeral docker container is spun up to execute the command.
Alternatively you can start single container and have it run in the background using ./bin/dev-env/start
.
That allows you to do things such as have the project running in one terminal, and be shell
ed into the development environment in another.
To stop, use: ./bin/dev-env/stop
.