static void getSlots(WrenVM* vm) { bool result = true; if (wrenGetSlotBool(vm, 1) != true) result = false; // TODO: Test wrenGetSlotForeign(). int length; const char* bytes = wrenGetSlotBytes(vm, 2, &length); if (length != 5) result = false; if (memcmp(bytes, "by\0te", length) != 0) result = false; if (wrenGetSlotDouble(vm, 3) != 12.34) result = false; if (strcmp(wrenGetSlotString(vm, 4), "str") != 0) result = false; WrenHandle* handle = wrenGetSlotHandle(vm, 5); if (result) { // Otherwise, return the value so we can tell if we captured it correctly. wrenSetSlotHandle(vm, 0, handle); wrenReleaseHandle(vm, handle); } else { // If anything failed, return false. wrenSetSlotBool(vm, 0, false); } }
void fileOpen(WrenVM* vm) { const char* path = wrenGetSlotString(vm, 1); uv_fs_t* request = createRequest(wrenGetSlotValue(vm, 2)); // TODO: Allow controlling flags and modes. uv_fs_open(getLoop(), request, path, O_RDONLY, 0, fileOpenCallback); }
void directoryList(WrenVM* vm) { const char* path = wrenGetSlotString(vm, 1); uv_fs_t* request = createRequest(wrenGetSlotValue(vm, 2)); // TODO: Check return. uv_fs_scandir(getLoop(), request, path, 0, directoryListCallback); }
static void setSlots(WrenVM* vm) { WrenHandle* handle = wrenGetSlotHandle(vm, 1); wrenSetSlotBool(vm, 1, true); wrenSetSlotBytes(vm, 2, "by\0te", 5); wrenSetSlotDouble(vm, 3, 1.5); wrenSetSlotString(vm, 4, "str"); // TODO: wrenSetSlotNull(). // Read the slots back to make sure they were set correctly. bool result = true; if (wrenGetSlotBool(vm, 1) != true) result = false; int length; const char* bytes = wrenGetSlotBytes(vm, 2, &length); if (length != 5) result = false; if (memcmp(bytes, "by\0te", length) != 0) result = false; if (wrenGetSlotDouble(vm, 3) != 1.5) result = false; if (strcmp(wrenGetSlotString(vm, 4), "str") != 0) result = false; if (result) { // Move the value into the return position. wrenSetSlotHandle(vm, 0, handle); } else { // If anything failed, return false. wrenSetSlotBool(vm, 0, false); } wrenReleaseHandle(vm, handle); }
void statPath(WrenVM* vm) { const char* path = wrenGetSlotString(vm, 1); uv_fs_t* request = createRequest(wrenGetSlotValue(vm, 2)); uv_fs_stat(getLoop(), request, path, statPathCallback); }