Events
Some things a mod hears about rather than asks for: a button it drew was pressed, or a setting changed. They arrive as events, after the mod's frame, through one export the mod writes and one import every mod has.
Taking events
Export on_event. After a mod's on_frame, the host calls it once for each event waiting for that
mod, with the event's id and the size of its payload. Inside it, axiom_event_read copies the payload
into a buffer of the mod's.
uint8_t s_Payload[128]; __attribute__((export_name("on_event"))) OnEvent(uint32_t id, uint32_t size) { (size > sizeof(s_Payload) || axiom_event_read(s_Payload, sizeof(s_Payload)) != AXIOM_EVENT_READ_OK) { ; } (id == AXIOM_EVENT_UI_OVERLAY_PRESSED) { AxiomUiOverlayPressedEvent* pressed = ( AxiomUiOverlayPressedEvent*)s_Payload; /* The id the mod gave the button, at an offset into the payload. */ (pressed->id.Offset + pressed->id.Length <= size) { char* button = ( char*)s_Payload + pressed->id.Offset; OnPressed(button, pressed->id.Length); } ; } (id == AXIOM_EVENT_CONFIG_CHANGED) { AxiomConfigChangedEvent* changed = ( AxiomConfigChangedEvent*)s_Payload; (changed->key.Offset + changed->key.Length <= size) { char* key = ( char*)s_Payload + changed->key.Offset; OnChanged(key, changed->key.Length); } } }
A mod without on_event takes no events, and that is not a fault: what was queued for it is
dropped.
Reading a payload
axiom_event_read(out, capacity) is imported from axiom:event. It is part of the ABI rather than a
capability, so every mod has it without declaring it.
The payload is the generated struct named for the event: the event's fields in the order the IDL
gives them. A string in it is an AxiomSpan whose Offset counts from the start of the payload, and
the strings' bytes follow the fixed part. Cast the buffer to the struct, then read each string at the
buffer plus its offset, after checking the offset and length fall inside size.
#define AXIOM_EVENT_UI_OVERLAY_PRESSED 0x44f17222u typedef AxiomUiOverlayPressedEvent { AxiomUiOverlayPanelId panel; AxiomSpan id; } AxiomUiOverlayPressedEvent;
Event ids
An event's id is FNV-1a over its full name, such as ui.overlay@1.pressed, so it is the same number
in every build and every language. surface.h defines a constant for each, and a struct for its
payload:
Which events arrive today
Two are delivered, both in the Sandbox:
ui.overlay@1 pressed, when a button the mod drew is pressed in the overlay. It goes to the mod that drew the button, as the host recorded who was drawing, never as the mod named itself.idis the id the mod gave the button, andpanelthe panel it was in.config@1 changed, once for each key whose value the person changed in the settings panel, to a mod that declaredconfig@1. Read the new value withconfig@1in the same callback or the next frame.
The others are declared in the surface and nothing sends them yet. A mod can handle them now and will hear them once a backend does.
Limits
- A mod hears only its own capabilities. It gets events only from capabilities it declared, the same way it can import only those.
- Sixteen a frame. At most sixteen events are delivered to a mod in one frame, out of the fuel its frame left. The rest wait for the next frame.
- Sixty-four waiting. A mod falling behind keeps the oldest sixty-four, and newer ones are dropped and counted.
- Next frame, not during the click. A press is delivered after the mod's next frame, never inside
the click, so input state read in
on_eventis the frame's, not the moment of the press.