nim-ffi/ffi.nim
Ivan FB 40cd6d2d26
feat(ffi): add {.ffiExport.} for simple synchronous C exports
{.ffi.}/{.ffiCtor.} cover the async, context-handle, CBOR-marshaled path.
{.ffiExport.} covers the complementary case: a no-argument lifecycle/health
entry point a host loads with dlopen+dlsym and calls synchronously — no
context, no callback, no CBOR, the return value crossing the ABI directly.

Native Nim return types are bridged to the C ABI (int/bool -> int,
uint64 -> unsigned long long, string -> const char* kept alive in shared
memory; no-return -> void), and initializeLibrary() is injected so the Nim
runtime is up on first call — the host never invokes NimMain itself.

Fills the no-argument scalar case of the declared-but-unimplemented abi=c path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0138fdSv6Xhv2KjhiyYR4SAu
2026-07-12 11:55:10 +02:00

15 lines
472 B
Nim

import std/[atomics, tables]
import chronos, chronicles
import
ffi/internal/[ffi_library, ffi_macro, ffi_export, c_wire],
ffi/[
alloc, ffi_types, ffi_events, ffi_handles, ffi_context, ffi_context_pool,
ffi_thread_request, cbor_serial,
]
export atomics, tables
export chronos, chronicles
export
atomics, alloc, ffi_library, ffi_macro, ffi_export, ffi_types, ffi_events, ffi_handles,
ffi_context, ffi_context_pool, ffi_thread_request, cbor_serial, c_wire