AppendixExamples
Callback Examples
Native and hybrid callback proofs using generated bindings and Kira-owned persistent callback state.
The callback examples prove that Kira can:
- generate a callback typedef binding from a C header
- pass a Kira
@Nativefunction as a real C ABI callback - call through that callback in native code
- do the same across the hybrid runtime/native boundary
- keep mutable Kira-owned callback state behind an opaque userdata token
Native Example
Run:
kira run --backend llvm examples/callbacksCurrent output:
callbacks
6
9
2
12That comes from:
- a manifest under
examples/callbacks/NativeLibs/callbacks.toml - a generated module at
examples/callbacks/callbacks.kira - a Kira
CounterStateboxed withnativeState(...) - an opaque token exported with
nativeUserData(...) - a native callback that mutates the boxed state with
nativeRecover(...)
Hybrid Example
The repo also carries a hybrid callback proof in:
tests/pass/run/ffi_callback_hybrid/That matters because it exercises:
- runtime entry execution
- native callback invocation
- runtime/native bridge marshalling
What This Proves
The callback examples are small, but they prove a lot of the current contract:
- generated callback typedefs are real Kira types
RawPtris the explicit user-data carriernativeState(...)avoids forcing globals for callback statenativeRecover(any)is typed recovery, not a raw layout cast@FFI.Struct { layout: c; }remains separate from opaque callback state- callback targets must match the generated signature exactly
- Kira does not invent closure capture semantics at the ABI boundary