mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-20 16:29:31 +00:00
Struct-returning methods now hand back a typed Go struct instead of the raw
CBOR/bytes. Since the native return POD is freed right after the callback, the
POD->Go conversion must happen in-callback: the generator emits a `fromC()`
reader per {.ffi.} type and, per struct-returning proc, an exported Go result
callback. The method calls the native entry point directly with that callback
and a `runtime/cgo.Handle` (boxed in a small C allocation so it travels through
the void* userData checkptr-safe), then blocks until the callback delivers the
typed value or error on the result slot.
String/raw-returning procs keep the existing C-bridge + condvar path. Validated
end-to-end (Echo/Complex/Schedule) including under `go run -race`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
timer example
This example is a self-contained Nimble project demonstrating how to import nim-ffi and use the .ffiCtor. / .ffi. abstraction.
Usage
-
Change into the example directory:
cd examples/timer -
Install the local
ffidependency:nimble install -y ../.. -
Build the example library:
nimble build -
Generate bindings:
nimble genbindings_rust nimble genbindings_cpp
Rust example clients
The Rust client lives in examples/timer/rust_client.
-
Run the sync example:
cd examples/timer/rust_client cargo run --bin rust_client -
Run the Tokio example:
cd examples/timer/rust_client cargo run --bin tokio_client
C++ example
The generated C++ example lives in examples/timer/cpp_bindings.
Build and run it with:
cd examples/timer/cpp_bindings
cmake -S . -B build
cmake --build build
./build/example