boomkat

reference

C embedding API (boomkat.h)

Core types and functions exported by include/boomkat.h. Build the static library with make lib or the shared library with make shared.

Core types

typedef struct bk_runtime_s *bk_runtime

Owns a heap, VM, value registry, job queue, module loader, memory limit, and interrupt hooks. Runs on one thread at a time.

typedef struct bk_ctx_s *bk_ctx

A realm within a runtime. Owns globals, intrinsics, module instances, pending exception, and diagnostics.

typedef uint64_t bk_value

Opaque 64-bit value handle. Owned registry root outside a local scope, or scope-bound local handle inside one.

typedef uint32_t bk_scope

Handle to an active local value scope (max 131,072 locals per scope).

Immediate handles

BK_UNDEFINED, BK_NULL, BK_TRUE, BK_FALSE, BK_BOOL(b), and BK_EXCEPTION. Immediate handles are valid across contexts, consume no registry slot, and require no bk_free_value.

Lifecycle

bk_ctx bk_create(void)

Create a standalone context that owns its own runtime.

void bk_destroy(bk_ctx ctx)

Destroy a context created by bk_create and its owned runtime.

bk_runtime bk_new_runtime(const bk_runtime_options *opts)

Create a runtime. Pass NULL for defaults, or supply custom allocator and fatal callbacks via bk_runtime_options.

void bk_free_runtime(bk_runtime rt)

Destroy a runtime and all realms created inside it.

bk_ctx bk_new_context(bk_runtime rt, const bk_context_options *opts)

Create a realm inside rt. Supports BK_CONTEXT_NO_EVAL, BK_CONTEXT_CANNOT_BLOCK, and BK_CONTEXT_HOST_GLOBAL.

void bk_free_context(bk_ctx ctx)

Release a context handle and clear its pending exception.

void bk_request_interrupt(bk_runtime rt)

Thread-safe interrupt latch for watchdog cancellation.

void bk_clear_interrupt(bk_runtime rt)

Clear a previously latched interrupt request.

Evaluation and exceptions

bk_value bk_eval(bk_ctx ctx, const char *source)

Evaluate a NUL-terminated sloppy script; returns an owned bk_value or BK_EXCEPTION.

bk_value bk_eval_ex(bk_ctx ctx, const char *source, size_t len, const char *filename, unsigned flags)

Evaluate source with explicit length, filename, and flags such as BK_EVAL_STRICT.

int bk_exec(bk_ctx ctx, const char *source)

Evaluate a script, discard the result, and return non-zero on failure.

int bk_is_exception(bk_value v)

Return non-zero if v is BK_EXCEPTION.

bk_value bk_get_exception(bk_ctx ctx)

Take and clear the pending thrown value. Returns BK_UNDEFINED if none is pending.

const char *bk_error(bk_ctx ctx)

Return a NUL-terminated diagnostic string for the last error.

Values, scopes, and host callbacks

bk_value bk_dup_value(bk_ctx ctx, bk_value v)

Create a new owned registry root for v. Immediates are returned unchanged.

void bk_free_value(bk_ctx ctx, bk_value v)

Release an owned registry root. Ignores immediates and local handles.

bk_scope bk_scope_open(bk_ctx ctx)

Open a nested local value scope. Value-returning calls allocate locals until the scope closes.

bk_value bk_scope_close_escape(bk_ctx ctx, bk_scope scope, bk_value v)

Close scope and return v in the enclosing scope (or as an owned root if none encloses it).

const char *bk_cstr(bk_ctx ctx, bk_value v, size_t *len_out)

Coerce v to context-owned UTF-8 valid for the next three bk_cstr calls.

int bk_register_fn(bk_ctx ctx, bk_value obj, const char *name, bk_native_fn fn, unsigned argc, unsigned flags, void *udata)

Register a C callback on obj (pass 0 for the global object).

Full C and C++ headers live in include/boomkat.h and include/boomkat.hpp.