Skip to main content

Module host

Module host 

Source
Expand description

The gasm ABI v0 host: instantiates a guest and implements the “gasm”, “gasm:gfx”, “gasm:net” and “gasm:storage” imports, plus the WASI subset in crate::wasi.

Structs§

Clipboard
The “copied only if it fits” convention: copy src to dst if src.len() <= cap; returns the full length either way. gasm:clipboard’s state. The runner owns the system clipboard: it sets pasted for the frame that carries the player’s paste key press (cleared after it) and takes copied after each frame. Headless runs never paste.
Fnv
FNV-1a 32-bit; mirrored in runners/web/gasm-host.js for cross-runner checks.
Game
A running guest. gasm_frame guests are called once per frame; gasm_run guests run in one suspended call (stack switching) that each Game::frame resumes until its next yield_frame.
Gamepad
Host
LoadOptions
How to load a guest.
MemoryLimit
The guest’s memory cap (--memory-limit): growing past it traps, with a message that says so (the JS runner checks after each guest call, with the same message).
Pointer
Profile
--profile <out.json>: wasmtime’s GuestProfiler sampling the main thread’s guest stacks every millisecond (an extra epoch ticker; call timeouts are off meanwhile), written in the Firefox Profiler’s format when the game ends. Only guest frames are recorded, and wasmtime checks the epoch only in guest code: the milliseconds a call into the runner (gasm:gl, ANGLE, …) took are samples of the guest stack it returns to, so they count for the function that called it. The time inside those calls is measured too (the call hook) and printed with the file.
RawInput
Raw input for one frame, set by the runner before each gasm_frame. None fields mean the runner has no such device (the import returns -1).
VirtualClock
Headless virtual time: derived from the frame number, monotonic when the guest changes its frame rate. Same arithmetic in gasm-host.js (VirtualClock) and the gasm::native stub.

Enums§

Stop
Why a guest call ended.

Constants§

ABI_VERSION
CLIPBOARD_MAX
The largest text gasm:clipboard passes either way
DEFAULT_MEMORY_LIMIT
The default memory cap: far above what the games here use (Godot’s 3D example: 39 MiB).
GAMEPAD_AXES
GAMEPAD_BUTTONS
GAMEPAD_BYTES
KEY_STATE_BYTES
POINTER_BYTES
TITLE_MAX_BYTES
Longest title set_title keeps, in UTF-8 bytes.

Functions§

clean_title
A guest’s set_title text as runners show it: control characters (Unicode Cc) and bidi controls (U+202A–U+202E, U+2066–U+2069) removed, then cut to 256 bytes at a character boundary. None: empty, the runner’s default. Same rules in runners/web/lib/host.js cleanTitle.
custom_section
The payload of custom section name in a wasm binary (None for a .cwasm or a malformed module: the loader reports those).
engine
The process-wide engine: the same configuration for compiling, precompiling and loading (.cwasm files must match it). Epoch interruption lets a guest call that never returns be stopped (LoadOptions::call_timeout). Calls can be sync (gasm_frame guests) or async (gasm_run guests: stack switching).
frame_position
Map a drawable position into the last video_present frame (letterboxed as the runners display it, present::letterbox). Same arithmetic in runners/web/lib/input.js.
imports_module
Whether a module imports anything from module (e.g. “gasm:gl”), read before loading it. A .cwasm is checked only with allow_precompiled (it is native code).
memory_limit_message
The trap message when a guest needs more memory than allowed (also the JS runner’s).
precompile
Ahead-of-time compile a guest to native code for this host (no JIT needed at load).
provided
What this runner provides (gasm.has), without a game (gasm-run --info).
static_title
The guest’s built-in title (custom section gasm.title, UTF-8), cleaned like set_title: the default title before (or without) set_title.