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_interopwill userunner.luato execute the scriptrunner.luawill wrap the script's return value in a "result" table, serialise it JSON using the lua-cjson library and then return it back tolua_interoplua_interopwill 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
luaas a WASM side module - Compile
lua-cjsoninto a WASM side module & rename atrifact tocjson.soto allow the lua runtime to dynamically load it at runtime - Compile
lua-interop.cinto a WASM main module
- bash on linux-like environment (for Windows use WSL2)
- Docker
- Docker Compose
- An
.editorconfigcompliant 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 shelled into the development environment in another.
To stop, use: ./bin/dev-env/stop.
