JavaScript

  • Template: cart_js - press "Use this template" and you have a working game.
  • Docker image: ghcr.io/notnullgames/null0-cart-quickjs:latest
  • Your code: cart/main.js, interpreted by QuickJS, baked into main.wasm
  • Bindings: carts/js/null0.d.ts (editor definitions - the runtime provides the API itself)
  • WASI is available, so ordinary file and stdio calls work.
  • See carts made with JavaScript
  • API docs for JavaScript

building

You do not install QuickJS, baked into main.wasm - 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-quickjs:latest mygame

The template wraps that in npm start, which also serves the result and rebuilds when you save.

JavaScript notes

  • The API is plain globals - nothing to import. Callbacks are ESM exports of main.js.
  • Structs are plain objects ({ r: 0, g: 121, b: 241, a: 255 }); array args know their own length, so you never pass the count.
  • std and os from QuickJS are available as globals, as is WASI.
  • Drop null0.d.ts + jsconfig.json next to main.js for editor completion and typechecking.

a cart, in JavaScript

This is carts/js/simple/main.js in the engine repo - the same file CI builds into the cart below, so it always compiles.

// the null0 API is available as plain globals - nothing to import. drop
// null0.d.ts next to this file for editor completion.

export function load () {
  clear(BLUE)
  draw_circle(100, 100, 50, RED)
  draw_text(FONT_DEFAULT, 'hello from JavaScript', 170, 92, WHITE)
}

// other callbacks you can export:
//
//   export function update () {}
//   export function unload () {}
//   export function buttonDown (button, player) {}
carts/js/simple/main.js

callbacks

A cart implements the callbacks it cares about. In JavaScript they look like this:

export function update () {}

See anatomy of a cart for the full list and what each one is passed.