Files
wren/test/api/get_value/get_value.c
Bob Nystrom 0b97b27cf4 Add an API for storing handles to values outside of the VM.
It's pretty bare bones now, but it lets you get a reference to an object
from a foreign call and then return it later.
2015-08-06 22:24:15 -07:00

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;
}