🅰️AssemblyScript is TypeScript with wasm types. Nearly the same syntax as a JavaScript cart, but it compiles to a real wasm module instead of shipping an interpreter.
- Template: cart_as - press "Use this template" and you have a working game.
- Docker image:
ghcr.io/notnullgames/null0-cart-assemblyscript:latest - Your code:
cart/main.ts, compiled with asc - Bindings:
carts/as/null0.ts(baked into the docker image for you) - WASI is available, so ordinary file and stdio calls work.
- See carts made with AssemblyScript
- API docs for AssemblyScript
building
You do not install asc - the docker image has it, and the current null0 bindings, baked in. There is nothing in your project to keep in sync with the engine.
docker run --rm --user $(id -u):$(id -g) \
-v ./cart:/src -v ./webroot:/out \
ghcr.io/notnullgames/null0-cart-assemblyscript:latest mygameThe template wraps that in npm start, which also serves the result and rebuilds when you save.
AssemblyScript notes
- Import what you use:
import { clear, draw_circle, BLUE } from 'null0.ts'- that exact specifier, not a relative path. - Functions taking text take a plain
string; the pointer conversion is done for you (the raw*_ptrimports are exported too, if you want them). - Built with
--runtime stub, so there is no GC - treat allocations as permanent.
a cart, in AssemblyScript
This is carts/as/simple/main.ts in the engine repo - the same file CI builds into the cart below, so it always compiles.
import { clear, draw_circle, draw_text, BLUE, RED, WHITE, FONT_DEFAULT } from 'null0.ts'
export function load(): void {
clear(BLUE)
draw_circle(100, 100, 50, RED)
draw_text(FONT_DEFAULT, 'hello from AssemblyScript', 170, 92, WHITE)
}
// other callbacks you can export:
//
// export function update(): void {}
carts/as/simple/main.tscallbacks
A cart implements the callbacks it cares about. In AssemblyScript they look like this:
export function load(): void {}See anatomy of a cart for the full list and what each one is passed.