cCatalystABIVersion
uint32_t cCatalystABIVersion(void);
Returns the C bridge’s ABI version, currently 1. Bindings can check it before using the handle and callback interfaces.
Language bindings
The C ABI for values, errors, runtimes, messengers, and servers.
#include <mc/CCatalyst.h>This header is usable from C. Fallible calls return NULL on success or an owned CErrorHandle* on failure. No exceptions may cross the boundary, including callbacks.
Returned handles are owned unless stated otherwise; release them with the matching release function. Keep a live handle for each call. Strings and buffers use explicit byte lengths.
Reads produce snapshots. Callback values are editable snapshots whose changes are committed before the callback returns. Callback parameters are borrowed; retain a messenger to keep it.
Only cvar, CMessenger, CServer, and their support types are exposed to Python and Swift.
typedef struct CVarHandle CVarHandle;
typedef struct CErrorHandle CErrorHandle;
typedef struct CRuntimeHandle CRuntimeHandle;
typedef struct CMessengerHandle CMessengerHandle;
typedef struct CServerHandle CServerHandle;
enum CVarType { CVarNone = 1, CVarNull = 2, CVarInteger = 5, CVarFloat = 6, CVarString = 7, CVarSymbol = 8, CVarVector = 9, CVarFunction = 10, CVarMap = 11, CVarBuffer = 12, CVarPacked = 13, CVarSet = 16, CVarBool = 4 };
typedef void (*CContextRelease)(void* context);
typedef CErrorHandle* (*CMessageCallback)(void* context, CMessengerHandle* messenger, CVarHandle* message, int* handled);
typedef CErrorHandle* (*CCloseCallback)(void* context, CMessengerHandle* messenger);
typedef CErrorHandle* (*CAdmitCallback)(void* context, CMessengerHandle* messenger, CVarHandle* auth, int* accepted);
uint32_t cCatalystABIVersion(void);
Returns the C bridge’s ABI version, currently 1. Bindings can check it before using the handle and callback interfaces.
const char* cErrorType(const CErrorHandle* error);
Returns the error type name as borrowed text.
const char* cErrorMessage(const CErrorHandle* error);
Returns text borrowed from the error; keep the error handle alive.
CErrorHandle* cErrorCause(const CErrorHandle* error);
Returns an owned handle for the retained cause, or NULL if no cause exists.
void cErrorRelease(CErrorHandle* error);
Releases an owned error handle. Borrowed message and type text must no longer be used afterward.
CErrorHandle* cErrorCreate(const char* message, size_t size);
Creates an owned error containing a copy of the given message bytes, for example to report a callback failure. This call returns the error itself, rather than a success-or-error status.
void cVarRetain(CVarHandle* value);
Adds an ownership reference to the same value handle. Use cVarCopy() when an independent value snapshot is needed.
void cVarRelease(CVarHandle* value);
Releases one ownership reference; the value is destroyed after its final release.
CErrorHandle* cVarCreate(uint8_t type, CVarHandle** out);
Creates an owned None, Null, Vector, Map, or Set handle. Other type codes require their corresponding typed constructors.
CErrorHandle* cVarInteger(int64_t value, CVarHandle** out);
Creates an owned value from a signed 64-bit integer.
CErrorHandle* cVarFloat(double value, CVarHandle** out);
Creates an owned floating-point value from a double.
CErrorHandle* cVarBool(int value, CVarHandle** out);
Creates an owned boolean value; zero means false and any other integer means true.
CErrorHandle* cVarBytes(uint8_t type, const void* bytes, size_t size, CVarHandle** out);
Copies the supplied byte range into an owned String, Symbol, or Buffer value. size is a byte count and excludes any optional trailing terminator.
CErrorHandle* cVarFunction(const char* name, size_t size, const CVarHandle* arguments, CVarHandle** out);
Creates a named function expression from the name bytes and a vector of arguments. Copies the arguments and computes its dispatch hash; this constructs data without invoking a function.
CErrorHandle* cVarCopy(const CVarHandle* value, CVarHandle** out);
Returns an owned snapshot of the value in a new handle. Subsequent assignment to the original handle does not replace this snapshot.
CErrorHandle* cVarAssign(CVarHandle* value, const CVarHandle* other);
Replaces the destination handle’s value with a snapshot of other. Other owners retaining the destination handle observe the replacement.
CErrorHandle* cVarGetTag(const CVarHandle* value, CVarTag* out);
Copies the stored type, flags, kind, and attributes into the output structure.
CErrorHandle* cVarSetTag(CVarHandle* value, CVarTag tag);
Updates metadata only. The supplied type must match the stored value.
CErrorHandle* cVarGetInteger(const CVarHandle* value, int64_t* out);
Reads an Integer value into the output. Other types return an error instead of applying numeric coercion.
CErrorHandle* cVarGetFloat(const CVarHandle* value, double* out);
Reads a Float value into the output. An Integer does not implicitly convert through this call.
CErrorHandle* cVarGetBool(const CVarHandle* value, int* out);
Reads a Bool value as zero or one. Other types return an error instead of applying truth-value conversion.
CErrorHandle* cVarGetBytes(const CVarHandle* value, CVarHandle** out);
Returns an owned Buffer snapshot of a string, symbol name, function name, or buffer. Use cVarSize() and cVarCopyBytes() on that snapshot to access its bytes.
CErrorHandle* cVarSize(const CVarHandle* value, size_t* out);
Returns the byte count for String or Buffer, element count for Vector, Set, or Map, or argument count for Function. Unsupported scalar types return an error.
CErrorHandle* cVarCopyBytes(const CVarHandle* value, void* out, size_t size);
Copies a Buffer’s bytes into caller-owned memory, requiring room for the entire buffer. Adds no terminator and leaves any unused trailing destination bytes untouched; first use cVarGetBytes() for text.
CErrorHandle* cVarGetIndex(const CVarHandle* value, size_t index, CVarHandle** out);
Returns an owned snapshot of a vector element or function argument. The index must be within the existing sequence.
CErrorHandle* cVarSetIndex(CVarHandle* value, size_t index, const CVarHandle* item);
Copies an item into an existing vector position or function argument. It does not extend the sequence or change a function’s name or arity.
CErrorHandle* cVarAppend(CVarHandle* value, const CVarHandle* item);
Copies an item into a Vector, Set, or Function, appending where order exists. Set insertion preserves uniqueness; function edits update the dispatch hash.
CErrorHandle* cVarGetKey(const CVarHandle* value, const char* key, size_t size, CVarHandle** out);
Returns an owned snapshot of a map value. Missing keys and non-map receivers return an error.
CErrorHandle* cVarSetKey(CVarHandle* value, const char* key, size_t size, const CVarHandle* item);
Inserts or replaces a map entry using copies of the key bytes and item value.
CErrorHandle* cVarHasKey(const CVarHandle* value, const char* key, size_t size, int* out);
Writes one if the map contains the key, otherwise zero. A non-map receiver returns an error.
CErrorHandle* cVarRemoveKey(CVarHandle* value, const char* key, size_t size);
Removes a key from a map, doing nothing if it is absent. Existing snapshots remain valid.
CErrorHandle* cVarEraseRange(CVarHandle* value, size_t position, size_t count);
Erases bytes from a string or elements from a vector/function. Counts are clamped at the end; earlier snapshots are unchanged.
CErrorHandle* cVarElements(const CVarHandle* value, CVarHandle** out);
Returns a vector of map keys or set elements, without an iteration-order guarantee.
CErrorHandle* cVarParse(const char* code, size_t size, CVarHandle** out);
Parses the supplied CSON text into an owned value. The result must belong to the C bridge’s supported value-interchange surface; parsing does not evaluate expressions.
CErrorHandle* cVarCSON(const CVarHandle* value, CVarHandle** out);
Formats the value as CSON and returns an owned String handle. Obtain its bytes through cVarGetBytes().
CErrorHandle* cVarStore(const CVarHandle* value, CVarHandle** out);
Serializes the existing Catalyst format with attached buffers inlined.
CErrorHandle* cVarRestore(const void* bytes, size_t size, CVarHandle** out);
Restores one supported value from serialized bytes and returns an owned handle. Copies the input and rejects trailing bytes after the value.
CErrorHandle* cRuntimeCreate(size_t workers, CRuntimeHandle** out);
Creates a runtime with a running worker pool. Child handles retain it.
void cRuntimeRetain(CRuntimeHandle* runtime);
Keeps the runtime alive for another owner. Messenger and server handles also retain their runtime automatically.
void cRuntimeRelease(CRuntimeHandle* runtime);
Releases one runtime ownership reference. Final cleanup is deferred so worker threads can shut down safely; cCatalystDrain() can wait for that cleanup.
CErrorHandle* cCatalystDrain(void);
Waits for deferred final releases. Does not close live resources. Never call from a callback; release language locks before waiting.
CErrorHandle* cMessengerCreate(CRuntimeHandle* runtime, CMessengerHandle** out);
Creates a disconnected messenger using the runtime’s worker pool. The returned handle owns a reference to that runtime.
void cMessengerRetain(CMessengerHandle* messenger);
Adds an ownership reference to the messenger. Retain a borrowed callback handle before keeping it beyond that callback.
void cMessengerRelease(CMessengerHandle* messenger);
Releases one ownership reference. Final messenger teardown is deferred; release every retained reference when finished.
CErrorHandle* cMessengerCallbacks(CMessengerHandle* messenger, void* context, CMessageCallback message, CCloseCallback closed, CContextRelease release);
Owns context only on successful registration. Replacement lets in-flight calls finish; NULL callbacks clear the registration. The release callback runs once after registration and calls finish.
CErrorHandle* cMessengerConnect(CMessengerHandle* messenger, const char* host, size_t size, int port, int* connected);
Attempts to connect to the supplied host and port and writes the connection result to connected. The host uses an explicit byte length; an error handle reports a failure of the operation itself.
CErrorHandle* cMessengerConnected(CMessengerHandle* messenger, int* connected);
Writes a snapshot of the current connection state as zero or one. A true result does not guarantee a later send will succeed.
CErrorHandle* cMessengerClose(CMessengerHandle* messenger);
Explicitly closes the connection. The handle remains valid for state inspection and eventual release.
CErrorHandle* cMessengerSend(CMessengerHandle* messenger, const CVarHandle* value, int mode);
Modes: 0 queues, 1 waits for local transmission, 2 replies. Input values are not consumed.
CErrorHandle* cMessengerCall(CMessengerHandle* messenger, const CVarHandle* value, CVarHandle** out);
Sends a snapshot of the request and waits for an owned reply. Uses the messenger’s single synchronous-call slot; do not call from that messenger’s receive callback.
CErrorHandle* cMessengerReceive(CMessengerHandle* messenger, double seconds, CVarHandle** out);
Negative seconds waits indefinitely. NULL output means timeout or clean closure; a received Null value is a non-NULL handle.
CErrorHandle* cMessengerSession(CMessengerHandle* messenger, CVarHandle** out);
Returns an owned snapshot of the session value. Editing the snapshot does not update the messenger until cMessengerSetSession() is called.
CErrorHandle* cMessengerSetSession(CMessengerHandle* messenger, const CVarHandle* value);
Replaces the session with a copy of the supplied value, without consuming the input handle.
CErrorHandle* cMessengerCallbackError(CMessengerHandle* messenger);
Retrieves and clears the last callback failure independently of receive().
CErrorHandle* cServerCreate(CRuntimeHandle* runtime, CServerHandle** out);
Creates a server retaining the given runtime. Register admission with cServerCallback() before expecting incoming connections to be accepted.
void cServerRetain(CServerHandle* server);
Adds an ownership reference to the same server handle.
void cServerRelease(CServerHandle* server);
Releases one ownership reference. Final teardown is deferred; cCatalystDrain() can wait for pending releases.
CErrorHandle* cServerCallback(CServerHandle* server, void* context, CAdmitCallback admit, CContextRelease release);
Registers admission. Without a callback, incoming connections are rejected. Retain an accepted messenger to keep it after admission.
CErrorHandle* cServerListen(CServerHandle* server, int port);
Starts listening on the requested port using the runtime’s worker pool. Incoming connections are handled by the registered admission callback.
CErrorHandle* cServerClose(CServerHandle* server);
Stops listening and closes connections still awaiting admission. Separately retained, admitted messengers remain responsible for their own connection lifetime.
CErrorHandle* cServerCallbackError(CServerHandle* server);
Retrieves and clears the last admission callback failure.
struct CVarTaguint8_t type;
uint8_t flags;
uint16_t kind;
uint32_t attrs;