mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-22 17:29:28 +00:00
Aligns the C++ generators with the C generator and the symbol naming: the native (zero-serialization, same-process) wrapper is the bare `<lib>.hpp` and the CBOR (inter-process) wrapper carries the `_cbor` suffix — mirroring the C headers (`<lib>.h` / `<lib>_cbor.h`) and the `<name>` / `<name>_cbor` exports. Previously native was `<lib>_native.hpp` and CBOR was the bare `<lib>.hpp`, which is backwards from the symbol convention and would collide on the native `<lib>.h` when both ABIs emit into one dir (ffiMode=both). With the flip, a single `genbindings_cpp` run now drops `<lib>.hpp` + `<lib>_cbor.hpp` side by side, exactly like c_bindings holds both `.h` headers. Consumers updated to match: the CBOR cpp_bindings driver and the C++ e2e suite include `*_cbor.hpp`; the native example includes the bare `<lib>.hpp`. Validated: native example runs on `my_timer.hpp`; C++ e2e suite 19/19 on the `_cbor.hpp` headers; check_bindings_cpp regen is deterministic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
66 lines
1.9 KiB
C
66 lines
1.9 KiB
C
// Generated by nim-ffi C codegen. Do not edit by hand.
|
|
//
|
|
// Native (zero-serialization) C ABI. Each call delivers its result to the
|
|
// callback. On RET_OK:
|
|
// - string-returning procs: (msg, len) is the raw string bytes (not
|
|
// NUL-terminated; use len).
|
|
// - struct-returning procs: msg is a pointer to the returned C struct — cast
|
|
// it to `const <Type>*` (len is sizeof). It is valid ONLY for the duration
|
|
// of the callback; copy out anything you need before returning. The library
|
|
// deep-frees it right after the callback (you free nothing).
|
|
// On RET_ERR, (msg, len) is the raw error text. A `<name>_cbor` variant of each
|
|
// proc also exists for generic/cross-language callers that prefer CBOR.
|
|
#ifndef NIM_FFI_GEN_ECHO_H
|
|
#define NIM_FFI_GEN_ECHO_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifndef NIM_FFI_RET_CODES
|
|
#define NIM_FFI_RET_CODES
|
|
#define RET_OK 0
|
|
#define RET_ERR 1
|
|
#define RET_MISSING_CALLBACK 2
|
|
#endif
|
|
|
|
#ifndef NIM_FFI_CALLBACK_T
|
|
#define NIM_FFI_CALLBACK_T
|
|
typedef void (*FFICallBack)(int callerRet, const char *msg, size_t len, void *userData);
|
|
#endif
|
|
|
|
|
|
// --- {.ffi.}-annotated types, exposed as C structs ----------
|
|
typedef struct {
|
|
const char* prefix;
|
|
} EchoConfig;
|
|
|
|
typedef struct {
|
|
const char* text;
|
|
} ShoutRequest;
|
|
|
|
typedef struct {
|
|
const char* shouted;
|
|
const char* prefix;
|
|
} ShoutResponse;
|
|
|
|
|
|
void *echo_create(EchoConfig config, FFICallBack callback, void *userData);
|
|
|
|
int echo_shout(void *ctx, FFICallBack callback, void *userData, ShoutRequest req);
|
|
|
|
int echo_version(void *ctx, FFICallBack callback, void *userData);
|
|
|
|
int echo_destroy(void *ctx);
|
|
|
|
uint64_t echo_add_event_listener(void *ctx, const char *eventName, FFICallBack callback, void *userData);
|
|
int echo_remove_event_listener(void *ctx, uint64_t listenerId);
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif
|
|
|
|
#endif /* NIM_FFI_GEN_ECHO_H */ |