Expand description
Rust bindings for the gasm game ABI v0 — see spec/ABI.md.
ⓘ
struct MyGame { t: u32 }
impl gasm::Game for MyGame {
fn init() -> Result<Self, String> { gasm::set_frame_rate(60.0); Ok(MyGame { t: 0 }) }
fn frame(&mut self) { self.t += 1; /* simulate, draw */ }
}
gasm::game!(MyGame);Build with --target wasm32-unknown-unknown and crate-type = ["cdylib"].
On native targets the same code links against an in-process stub host
(native) for tests and benchmarks.
Modules§
- audio
- gfx
- GPU rendering through
gasm:gfx(a WebGPU subset; descriptors are JSON). - native
- In-process stub host for running a guest natively (non-wasm targets).
- net
- Message connections through
gasm:net(WebSocket semantics, non-blocking). - storage
- Persistent per-game key/value store (
gasm:storage): saves, settings, scores. - sys
- Raw ABI. On wasm32 these are the real imports (see spec/ABI.md). On other
targets they are backed by
crate::native, an in-process stub host used for native parity tests and benchmarks.
Macros§
Structs§
- Buttons
- Virtual gamepad buttons (bit positions per spec/ABI.md).
Constants§
Traits§
- Game
- A gasm game.
initruns once;frameruns at the configured frame rate.
Functions§
- asset
- Read a whole asset.
- asset_
read_ at - Read up to
buf.len()bytes of an asset starting atoffset(for streaming large assets). Returns bytes read (0 at the end), orNoneif missing. - exit
- End the game (WASI
proc_exit). Runners treat code 0 as a clean exit. - log
- pad
- Buttons held on virtual pad
player(0..=3) this frame. - param
- Launch parameter (
--param k=vnatively,?k=vin the browser). - present
- Present an RGBA8 frame (
stridebytes per row). - set_
frame_ rate - Rate at which the runner calls
frame(). Default 60. - time_ms
- Monotonic milliseconds (virtual, frame-derived time in headless runs).