feat: add wrenReturnNull and wrenReturnString functions for FFI string and null support

Add two new public API functions to the Wren VM for foreign function interface
(FFI) return values. wrenReturnNull sets the foreign call slot to a null value,
while wrenReturnString copies the provided text into a new Wren heap string,
supporting both explicit length and strlen-based length calculation. Both
functions include assertions to ensure they are called within a valid foreign
call context.
This commit is contained in:
Bob Nystrom
2014-02-05 14:30:20 +00:00
parent 86015f4e48
commit 01ff51191b
2 changed files with 34 additions and 0 deletions
+19
View File
@@ -1166,3 +1166,22 @@ void wrenReturnDouble(WrenVM* vm, double value)
*vm->foreignCallSlot = NUM_VAL(value);
vm->foreignCallSlot = NULL;
}
void wrenReturnNull(WrenVM* vm)
{
ASSERT(vm->foreignCallSlot != NULL, "Must be in foreign call.");
*vm->foreignCallSlot = NULL_VAL;
vm->foreignCallSlot = NULL;
}
void wrenReturnString(WrenVM* vm, const char* text, int length)
{
ASSERT(vm->foreignCallSlot != NULL, "Must be in foreign call.");
size_t size = length;
if (length == -1) size = strlen(text);
*vm->foreignCallSlot = wrenNewString(vm, text, size);
vm->foreignCallSlot = NULL;
}