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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user