This is an opinionated binding for Wasm4 in MoonBit.
- MoonBit toolchain
- Node.js
- Add this package:
moon add moonbitlang/wasm4 - Develop with this package as other packages
- Optionally export a function called
startthat will be executed once on initialization and export a function calledupdatethat will be executed at 60Hz for the expected backend - Import a memory with the module of
envand name ofmemory - Build with
moon build --target <wasm-gc or wasm>with the respective backend - Execute
npx wasm4 run <target>.wasm. The target should be located intarget/wasm/release/build/<package path>/<package name>.wasmfor wasm backend, ortarget/wasm-gc/release/build/<package path>/<package name>.wasmfor wasm-gc backend. The browser should open automatically and display the game. Enjoy
The snake example (adapted from the Wasm4 documentation) demonstrates the usage. You may execute
moon build --source-dir example/snake --target wasm
npx wasm4 run example/snake/target/wasm/release/build/snake.wasmand enjoy the game.
- For more information about MoonBit, visit: MoonBit official website
- For more information about Wasm4 and how to play, visit: WASM-4 Documentation