You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- You **declare a library** once with `declareLibrary(name, LibType)`.
21
21
- You **annotate procs and types** with pragmas (`{.ffi.}`, `{.ffiCtor.}`,
22
-
`{.ffiDtor.}`, `{.ffiEvent.}`).
22
+
`{.ffiDtor.}`, `{.ffiStatic.}`, `{.ffiEvent.}`).
23
23
- You **call `genBindings()` last**, which emits the foreign bindings.
24
24
25
25
By default, every request/response crosses the boundary as a single CBOR blob
@@ -78,6 +78,7 @@ The generated C export names are the snake_case form of the proc names, e.g.
78
78
|`declareLibrary(name, LibType[, defaultABIFormat])`| call | Registers the library, its state type, and the default wire format. Must run before any annotation. |
79
79
|`{.ffi.}` on a `type`|`object`| Registers the type for binding generation; it serializes via the library's ABI format (CBOR by default). |
80
80
|`{.ffi.}` on a `proc`| proc | Exposes a method. First param is the library value, then typed params; returns `Future[Result[T, string]]`. |
81
+
|`{.ffiStatic.}`| proc | Exposes a context-independent proc: no library param, and its wrapper takes no ctx — see below. |
81
82
|`{.ffiCtor.}`| proc | The constructor. Returns `Future[Result[LibType, string]]`; creates the FFI context. |
82
83
|`{.ffiDtor.}`| proc | The destructor. Exactly one param `(x: LibType)`; tears the context down. |
83
84
|`{.ffiEvent[: "wire_name"].}`| proc (empty body) | A library-initiated callback. Call the proc from any `{.ffi.}` handler to fire it. The wire name is optional — see below. |
@@ -91,6 +92,44 @@ Every `{.ffi.}` / `{.ffiCtor.}` proc must have an explicit
91
92
`return ok(...)` without awaiting). The `Result`'s error string is delivered to
92
93
the foreign caller as the failure message.
93
94
95
+
### Context-independent procs
96
+
97
+
A `{.ffi.}` proc is a method: it takes the library value and its wrapper takes a
98
+
`ctx`, so the host must construct the library to call it. A stateless utility
99
+
shouldn't have to pay for that. Annotate it `{.ffiStatic.}` instead — drop the
100
+
library param, and the ctx disappears from the generated wrapper:
0 commit comments