⚡C is the most direct way to write a null0 cart - the API was designed as a C header, and every other language is a wrapper around it. Small carts, no runtime, no surprises.
- Template: cart_c - press "Use this template" and you have a working game.
- Docker image:
ghcr.io/notnullgames/null0-cart-c:latest - Your code:
cart/main.c, compiled with wasi-sdk clang - Bindings:
carts/c/null0.h(baked into the docker image for you) - WASI is available, so ordinary file and stdio calls work.
- See carts made with C
- API docs for C
building
You do not install wasi-sdk clang - 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-c:latest mygameThe template wraps that in npm start, which also serves the result and rebuilds when you save.
C notes
#include "null0.h"and you have the whole API.main()works as aload()if you prefer it.- Call
fflush(stdout)if you wantprintfoutput to survive a cart being killed.
a cart, in C
This is carts/c/simple/main.c in the engine repo - the same file CI builds into the cart below, so it always compiles.
#include "null0.h"
// every language's `simple` cart draws exactly this, so you can put any two
// of them side by side and see only the language differ
int main() {
clear(BLUE);
draw_circle(100, 100, 50, RED);
draw_text(FONT_DEFAULT, "hello from C", 170, 92, WHITE);
return 0;
}
// callbacks (optional - implement as needed)
// void update() {}
// void unload() {}
// void buttonUp(GamepadButton button, u32 player) {}
// void buttonDown(GamepadButton button, u32 player) {}
// void keyUp(Key key) {}
// void keyDown(Key key) {}
// void mouseDown(MouseButton button) {}
// void mouseUp(MouseButton button) {}
// void mouseMoved(f32 x, f32 y) {}
carts/c/simple/main.ccallbacks
A cart implements the callbacks it cares about. In C they look like this:
void update() {}See anatomy of a cart for the full list and what each one is passed.