https://github.com/peterhellberg/w4
A small Zig ⚡ module, primarily meant for my own experiments with WASM-4
https://github.com/peterhellberg/w4
wasm4 zig-package
Last synced: 8 months ago
JSON representation
A small Zig ⚡ module, primarily meant for my own experiments with WASM-4
- Host: GitHub
- URL: https://github.com/peterhellberg/w4
- Owner: peterhellberg
- License: mit
- Created: 2023-11-23T20:51:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-15T15:29:03.000Z (10 months ago)
- Last Synced: 2025-05-08T09:46:22.440Z (9 months ago)
- Topics: wasm4, zig-package
- Language: Zig
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# w4 :zap:
A small [Zig](https://ziglang.org/) ⚡ module, primarily meant for my own experiments with [WASM-4](https://wasm4.org/) 🎮
Based on the [wasm4.zig template](https://github.com/aduros/wasm4/blob/main/cli/assets/templates/zig/src/wasm4.zig)
> [!IMPORTANT]
> You might want to install the [w4-init](https://github.com/peterhellberg/w4-init) tool and use that instead of manually creating the files for your cart.
## Usage
You can have `zig build` retrieve the `w4` module if you specify it as a dependency.
### Create a `build.zig.zon` that looks something like this:
```zig
.{
.name = .w4_game,
.fingerprint = 0x9364c2ea98294635,
.version = "0.0.0",
.paths = .{""},
.dependencies = .{
.w4 = .{
.url = "https://github.com/peterhellberg/w4/archive/refs/tags/v0.1.0.tar.gz",
},
},
}
```
> [!NOTE]
> If you leave out the hash then `zig build` will tell you that it is missing the hash, and what it is.
> Another way to get the hash is to use `zig fetch`, this is probably how you _should_ do it :)
### Then you can add the module in your `build.zig` like this:
```zig
// Add the w4 module to the executable
exe.addModule("w4", b.dependency("w4", .{}).module("w4"));
```
### In your `src/main.zig` you should now be able to:
```zig
const w4 = @import("w4");
export fn start() void {}
export fn update() void {
const hello = "Hello from Zig!";
w4.color(2);
w4.text(hello, 15, 11);
w4.color(3);
w4.text(hello, 16, 10);
}
```