Ivan FB df6dd76311
feat(host): C ABI for {.ffiHost.} + cross-thread e2e
Increment 4: the exported C surface for host callbacks, plus an end-to-end
test that the host can answer from a different thread than the FFI loop.

- declareLibrary now emits two exportc/cdecl procs on every library's
  FFIContext (like the event ABI):
    <lib>_register_host_fn(ctx, name, fn, userData)
    <lib>_host_complete(ctx, token, ret, msg, len)
  (the `name` param is spelled `hostFnName` to dodge the macros.name capture
  under quote, same class as the existing id/ret collisions.)
- c.nim emits the FFIHostFn typedef + both declarations into <lib>.h
  (guarded, format-agnostic), and the timer header is regenerated.
- Verified: the built timer lib exports both symbols.

The e2e (test_ffi_host_e2e) drives the real bridge: a {.ffi.} handler awaits a
{.ffiHost.} call; the host fn (invoked on the FFI thread, non-blocking) hands
the work to a worker thread, which answers via the completion path. The result
resolves on the loop thread and round-trips correctly (orc+refc). It calls the
underlying registerHostFn/completeHostCall directly, since the exported shims
need an --app:lib build; those shims are verified by the symbol check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 23:32:38 +02:00
2026-05-19 12:43:34 +02:00
2026-05-21 16:33:38 +02:00
2026-05-20 14:14:42 -03:00
2026-05-20 14:14:42 -03:00
2026-05-16 01:08:42 +02:00
2026-05-20 14:14:42 -03:00
2026-05-20 14:14:42 -03:00

nim-ffi

Allows exposing Nim projects to other languages

Example

examples/timer is now a self-contained Nimble project that imports nim-ffi directly. Use cd examples/timer && nimble install -y ../.. && nimble build to compile the example.

Description
Allows exposing Nim projects to other languages
Readme
Languages
Nim 87.9%
Smarty 5.9%
C++ 4.8%
CMake 1.4%