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.
This commit is contained in:
Bob Nystrom
2015-08-06 22:24:15 -07:00
parent a1424f8371
commit 0b97b27cf4
13 changed files with 167 additions and 22 deletions
+24
View File
@@ -0,0 +1,24 @@
#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;
}
+3
View File
@@ -0,0 +1,3 @@
#include "wren.h"
WrenForeignMethodFn getValueBindForeign(const char* signature);
+14
View File
@@ -0,0 +1,14 @@
class Api {
foreign static value=(value)
foreign static value
}
Api.value = ["list", "of", "strings"]
// Do some stuff to trigger a GC (at least when GC stress testing enabled).
var s = "string"
for (i in 1...10) {
s = s + " more"
}
IO.print(Api.value) // expect: [list, of, strings]