Setup Your Project
Before you can begin, you need a project to work with. The CLI-Tool of WASM-4 includes templates for several programming languages like AssemblyScript, C, Go and Rust. More languages are sure to come in the future.
#
The TerminalWork is often easier on a terminal. For this step, open your terminal/powershell and navigate to your projects folder.
For the sake of having the same base, I assume the projects-folder is here: ~/Projects/
.
On Linux and macOS this is usually /home/[YOUR USERNAME]/Projects
.
On Windows this is usually C:\Users\[YOUR USERNAME]\Projects\
.
Below you'll find instructions for your language.
To compile AssemblyScript projects you will need npm
installed.
w4 new --assemblyscript snakecd snake
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 watch
To compile C/C++ projects you will need to download the WASI SDK and set the $WASI_SDK_PATH
environment variable.
w4 new --c snakecd snake
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 watch
Work in Progress
The tutorial for D is currently a Work-in-Progress. Most of the language specific instructions are currently missing.
To compile D projects you will need to download the WASI SDK and set the $WASI_SDK_PATH
environment variable.
w4 new --d snakecd snake
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 watch
To compile Go projects you will need go
and tinygo
installed.
w4 new --go snakecd snake
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 watch
To compile Nelua projects you will need nelua
installed.
w4 new --nelua snakecd snake
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 watch
Work in Progress
The tutorial for Nim is currently a Work-in-Progress. Most of the language specific instructions are currently missing.
To compile Nim projects you will need to download the WASI SDK and set the $WASI_SDK_PATH
environment variable.
w4 new --nim snakecd snake
Compile the .wasm cartridge:
nimble rel
Run it in WASM-4 with:
w4 watch
Work in Progress
The tutorial for Odin is currently a Work-in-Progress. Most of the language specific instructions are currently missing.
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 --nim snakecd snake
Compile the .wasm cartridge:
nimble rel
Run it in WASM-4 with:
w4 watch
Work in Progress
The tutorial for Porth is currently a Work-in-Progress. Most of the language specific instructions are currently missing.
To compile Porth projects you will need to download 4orth and add it to $PATH
.
w4 new --porth snakecd snake
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 watch
#
RequirementsTo compile Rust projects you will need to install the rust toolchain using rustup then add wasm32-unknown-unknown
target:
rustup target add wasm32-unknown-unknown
Binaryen
Create a new project
w4 new --rust snakecd snake
Compile the .wasm cartridge:
cargo build --release
Run it in WASM-4 with:
w4 watch
To compile WebAssembly Text projects you will need to download WABT and set the $WABT_PATH
environment variable.
w4 new --wat snakecd snake
Compile the .wasm cartridge:
make
Run it in WASM-4 with:
w4 watch
To compile zig projects you will need zig
installed.
w4 new --zig snakecd snake
Compile the .wasm cartridge:
zig build -Doptimize=ReleaseSmall
Run it in WASM-4 with:
w4 watch
Prevent Browser from opening
If you don't want the browser to open a new tab for you, you can prevent this by using the -n
or --no-open
option. You can also set an environment variable called W4_NO_OPEN
.
Examples:
w4 watch --no-open
or
W4_NO_OPEN=1 w4 watch
Setting a default language
You can set a default language by setting the environment variable W4_LANG
to one of the supported languages.
It's possible to override it with the CLI parameter later on.
#
Current StateFor now, your game should look this:
The color changes if you press Button 1
(X or Space).