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
#
QuickstartLet'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-world
First we'll setup AssemblyScript (this only needs to be done once):
npm install
Compile the .wasm cartridge:
npm run build
Run it in WASM-4 with:
w4 run build/cart.wasm
To compile C/C++ projects you will need to download the WASI SDK and set the $WASI_SDK_PATH
environment variable.
w4 new --c hello-world
For a C++ project pass --cpp
instead of --c
like this:
w4 new --cpp hello-world
Compile the .wasm cartridge:
cd hello-worldmake
Run it in WASM-4 with:
w4 run build/cart.wasm
To 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-world
Compile the .wasm cartridge from within the project directory:
c3c build
Run it in WASM-4 with:
w4 run cart.wasm
To 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-world
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 run cart.wasm
To compile Go projects you will need go
and tinygo
installed.
w4 new --go hello-worldcd hello-world
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 run build/cart.wasm
To 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-world
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 run build/cart.wasm
To 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-world
Compile the .wasm cartridge:
nimble rel
Run it in WASM-4 with:
w4 run build/cart.wasm
To 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-world
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 run build/cart.wasm
note
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-world
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 run build/cart.wasm
note
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-world
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 run build/cart.wasm
note
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-world
Compile the .wasm cartridge:
rolandc cart.rol --wasm4
Run it in WASM-4 with:
w4 run cart.wasm
To 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-world
Compile the .wasm cartridge:
cargo build --release
Run it in WASM-4 with:
w4 run target/wasm32-unknown-unknown/release/cart.wasm
To compile WebAssembly Text projects you will need to download WABT and set the $WABT_PATH
environment variable.
w4 new --wat hello-worldcd hello-world
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 run build/cart.wasm
To compile Zig projects you will need a recent build of zig
installed.
w4 new --zig hello-worldcd hello-world
Compile the .wasm cartridge:
zig build -Doptimize=ReleaseSmall
Run it in WASM-4 with:
w4 run zig-out/bin/cart.wasm
tip
You can also use w4 watch
to automatically watch for changes in source files and rebuild in real-time.
#
Next StepsNext let's take a look at some source code for Hello World.