Introduce WrenValue type and wrenGetArgumentValue/wrenReleaseValue functions to allow C code to hold GC-safe references to Wren objects across foreign calls. Implement doubly-linked list management in VM struct, mark value handles during garbage collection, and add assertion in wrenFreeVM to detect unreleased values. Update test infrastructure with new get_value test case and rename existing test binding functions to camelCase convention.
25 lines
468 B
C
25 lines
468 B
C
#include <string.h>
|
|
|
|
#include "get_value.h"
|
|
|
|
static WrenValue* value;
|
|
|
|
static void setValue(WrenVM* vm)
|
|
{
|
|
value = wrenGetArgumentValue(vm, 1);
|
|
}
|
|
|
|
static void getValue(WrenVM* vm)
|
|
{
|
|
wrenReturnValue(vm, value);
|
|
wrenReleaseValue(vm, value);
|
|
}
|
|
|
|
WrenForeignMethodFn getValueBindForeign(const char* signature)
|
|
{
|
|
if (strcmp(signature, "static Api.value=(_)") == 0) return setValue;
|
|
if (strcmp(signature, "static Api.value") == 0) return getValue;
|
|
|
|
return NULL;
|
|
}
|