Setup
Download WASM-4:
📥 Windows📥 macOS📥 Linux
This contains the w4 command that will be used to create new projects and run games locally.
info
You can also install w4 with NPM by running npm install -g wasm4
Quickstart#
Let's go over creating a new project called hello-world for your chosen language. Use the dropdown
menu to select a different language.
To compile AssemblyScript projects you will need npm installed.
w4 new --assemblyscript hello-worldcd hello-worldFirst we'll setup AssemblyScript (this only needs to be done once):
npm installCompile the .wasm cartridge:
npm run buildRun it in WASM-4 with:
w4 run build/cart.wasmTo compile C/C++ projects you will need to download the WASI SDK and set the $WASI_SDK_PATH environment variable.
w4 new --c hello-worldFor a C++ project pass --cpp instead of --c like this:
w4 new --cpp hello-worldCompile the .wasm cartridge:
cd hello-worldmakeRun it in WASM-4 with:
w4 run build/cart.wasmTo compile WASM-4 cartridges written in C3 you will need the C3 compiler. The sample project uses freestanding WASM, so some libc-dependent features are unavailable.
w4 new --c3 hello-worldcd hello-worldCompile the .wasm cartridge from within the project directory:
c3c buildRun it in WASM-4 with:
w4 run cart.wasmTo compile D projects you will need ldc and dub installed. To use libc, you also need to download the WASI SDK and set the $WASI_SDK_PATH environment variable.
w4 new --d hello-worldcd hello-worldCompile the .wasm cartridge:
makeRun it in WASM-4 with:
w4 run cart.wasmTo compile Go projects you will need go and tinygo installed.
w4 new --go hello-worldcd hello-worldCompile the .wasm cartridge:
makeRun it in WASM-4 with:
w4 run build/cart.wasmTo compile nelua projects you will need nelua installed. You will also need to download the WASI SDK and set the $WASI_SDK_PATH environment variable.
w4 new --nelua hello-worldcd hello-worldCompile the .wasm cartridge:
makeRun it in WASM-4 with:
w4 run build/cart.wasmTo compile Nim projects you will need nimble installed. You will also need to download the WASI SDK and set the $WASI_SDK_PATH environment variable.
w4 new --nim hello-worldcd hello-worldCompile the .wasm cartridge:
nimble relRun it in WASM-4 with:
w4 run build/cart.wasmTo compile Odin projects you will need to download the WASI SDK and set the $WASI_SDK_PATH environment variable. You'll also need the latest version of Odin.
w4 new --odin hello-worldcd hello-worldCompile the .wasm cartridge:
makeRun it in WASM-4 with:
w4 run build/cart.wasmnote
Penne is a work-in-progress esoteric language, so there are no stability guarantees. Your feedback is highly appreciated.
To compile WASM-4 cartridges written in Penne you will need a Penne compiler and a wasm-compatible version of clang. The easiest way is to download the WASI SDK and set the $WASI_SDK_PATH environment variable.
w4 new --penne hello-worldcd hello-worldCompile the .wasm cartridge:
makeRun it in WASM-4 with:
w4 run build/cart.wasmnote
Porth is currently a work in progress language. Anything can change at any moment without notice.
To compile Porth projects you will need to download 4orth and add it to $PATH.
w4 new --porth hello-worldcd hello-worldCompile the .wasm cartridge:
makeRun it in WASM-4 with:
w4 run build/cart.wasmnote
Roland is still under development. There are no stability guarantees, but your feedback will be highly influential!
To compile Roland projects you will need to download rolandc binary and put it on your path.
w4 new --roland hello-worldcd hello-worldCompile the .wasm cartridge:
rolandc cart.rol --wasm4Run it in WASM-4 with:
w4 run cart.wasmTo compile Rust projects you will need cargo installed. You will also need the wasm32 target,
which can be installed with rustup target add wasm32-unknown-unknown.
w4 new --rust hello-worldcd hello-worldCompile the .wasm cartridge:
cargo build --releaseRun it in WASM-4 with:
w4 run target/wasm32-unknown-unknown/release/cart.wasmTo compile WebAssembly Text projects you will need to download WABT and set the $WABT_PATH environment variable.
w4 new --wat hello-worldcd hello-worldCompile the .wasm cartridge:
makeRun it in WASM-4 with:
w4 run build/cart.wasmTo compile Zig projects you will need a recent build of zig installed.
w4 new --zig hello-worldcd hello-worldCompile the .wasm cartridge:
zig build -Doptimize=ReleaseSmallRun it in WASM-4 with:
w4 run zig-out/bin/cart.wasmtip
You can also use w4 watch to automatically watch for changes in source files and rebuild in real-time.
Next Steps#
Next let's take a look at some source code for Hello World.