mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Most of the pieces are there: - You can declare a foreign class. - It will call your C function to provide an allocator function. - Whenever a foreign object is created, it calls the allocator. - Foreign methods can access the foreign bytes of an object. - Most of the runtime checking is in place for things like subclassing foreign classes. There is still some loose ends to tie up: - Finalizers are not called. - Some of the error-handling could be better. - The GC doesn't track how much memory a marked foreign object uses.
25 lines
460 B
C
25 lines
460 B
C
#include <string.h>
|
|
|
|
#include "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 valueBindMethod(const char* signature)
|
|
{
|
|
if (strcmp(signature, "static Api.value=(_)") == 0) return setValue;
|
|
if (strcmp(signature, "static Api.value") == 0) return getValue;
|
|
|
|
return NULL;
|
|
}
|