// squirrelAdapter.h -- Squirrel 3.2 engine adapter for the broker.
//
// Exposes broker-registered native functions into a Squirrel VM, marshals values
// between Squirrel and CalogValueT by value (binary-safe strings; array/table <-> the
// hybrid aggregate). Built against the vendored Squirrel with -D_SQ64
// -DSQUSEDOUBLE so SQInteger/SQFloat are 64-bit int / double, matching CalogValueT.
//
// A Squirrel closure crossing the boundary becomes a refcounted CalogFnT over a
// pinned HSQOBJECT (sq_addref/sq_release, mirroring Lua's luaL_ref lifecycle):
// calogSquirrelExport fetches a named global closure, and a closure passed as a native
// argument is exported the same way during ingress marshalling. A foreign CalogFnT going
// the other way (pushed INTO Squirrel) becomes a native closure whose one free variable
// is a release-hooked userdata, so a script can call it directly. As with Lua, release
// every exported CalogFnT BEFORE calogSquirrelDestroy, since sq_release touches the VM.

#ifndef SQUIRREL_ADAPTER_H
#define SQUIRREL_ADAPTER_H

#include "calogInternal.h"

typedef struct CalogSquirrelT CalogSquirrelT;

int32_t calogSquirrelCreate(CalogSquirrelT **out, CalogT *broker, uint64_t ctxId);
void    calogSquirrelDestroy(CalogSquirrelT *context);
int32_t calogSquirrelExport(CalogSquirrelT *context, const char *globalName, CalogFnT **out);
int32_t calogSquirrelExpose(CalogSquirrelT *context, const char *name);
int32_t calogSquirrelRun(CalogSquirrelT *context, const char *source);

#endif
