Generate the Zig wrapper source from a boundary spec (pure). A spec and the user's body go in, a string of readable Zig comes out.
For a scalar function the wrapper is an export fn (C ABI, so FFM can
bind it) whose parameters are the native params and whose body is the
user's Zig spliced in verbatim:
export fn clj_zig_app_2e_core_add(x: i64, y: i64) i64 {
return x + y;
}
zig fmt owns final formatting; the generator emits already-canonical
Zig for the structure it controls, and the compile shell runs zig fmt over the whole file to normalize the body.
Generate the Zig wrapper source from a boundary spec (pure). A spec
and the user's body go in, a string of readable Zig comes out.
For a scalar function the wrapper is an `export fn` (C ABI, so FFM can
bind it) whose parameters are the native params and whose body is the
user's Zig spliced in verbatim:
export fn clj_zig_app_2e_core_add(x: i64, y: i64) i64 {
return x + y;
}
`zig fmt` owns final formatting; the generator emits already-canonical
Zig for the structure it controls, and the compile shell runs `zig
fmt` over the whole file to normalize the body.(generate spec body)(generate spec body {:keys [mode entry]})Emit the Zig wrapper for spec. In the default inline mode the user's
body string is spliced in; an error-union return generates an inner
impl fn and a translating wrapper, an owned or borrowed slice return
writes its pointer and length to out-params, a struct return writes
through an out-pointer, and every other return is a direct export fn.
In file mode (opts {:mode :file :entry "name"}) the wrapper instead
reconstructs its arguments and calls the user's pub fn; body is not
spliced and is concatenated separately.
Emit the Zig wrapper for `spec`. In the default inline mode the user's
`body` string is spliced in; an error-union return generates an inner
impl fn and a translating wrapper, an owned or borrowed slice return
writes its pointer and length to out-params, a struct return writes
through an out-pointer, and every other return is a direct `export fn`.
In file mode (`opts {:mode :file :entry "name"}`) the wrapper instead
reconstructs its arguments and calls the user's `pub fn`; `body` is not
spliced and is concatenated separately.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |