Skip to content

Instantly share code, notes, and snippets.

@avivbeeri
Last active October 24, 2019 08:18
Show Gist options
  • Save avivbeeri/786405c5d4a1247b3af29797514b10b2 to your computer and use it in GitHub Desktop.
Save avivbeeri/786405c5d4a1247b3af29797514b10b2 to your computer and use it in GitHub Desktop.
Minimal case for foreign allocate issue with wrenEnsureSlot
#include <stdio.h>
#include "wren.h"
void TEST_allocate(WrenVM* vm) {
// HERE:
// Changing the number of slots to be n + 2 where n is the number of arguments
// for the foreign class constructor causes an error to occur.
// It looks like Wren get's confused about what the return value
// is supposed to be.
wrenEnsureSlots(vm, 2);
wrenSetSlotNewForeign(vm, 0, 0, sizeof(int*));
wrenGetSlotHandle(vm, 0);
}
void error(
WrenVM* vm,
WrenErrorType type,
const char* module,
int line,
const char* message) {
printf("Err: %s", message);
}
void write(WrenVM* vm, const char* text)
{
printf("%s", text);
}
WrenForeignClassMethods bindForeignClass(
WrenVM* vm, const char* module, const char* className) {
WrenForeignClassMethods methods;
methods.allocate = TEST_allocate;
methods.finalize = NULL;
return methods;
}
int main() {
WrenConfiguration config;
wrenInitConfiguration(&config);
config.writeFn = write;
config.errorFn = error;
config.bindForeignClassFn = bindForeignClass;
WrenVM* vm = wrenNewVM(&config);
WrenInterpretResult result = wrenInterpret(
vm,
"something",
"foreign class Test { construct init() {} }\n"
"System.print(\"Test\")\nTest.init()"
);
wrenFreeVM(vm);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment