示例#1
0
文件: slots.c 项目: iwillspeak/wren
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);
  }
}
示例#2
0
文件: io.c 项目: graphitemaster/wren
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);
}
示例#3
0
文件: io.c 项目: graphitemaster/wren
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);
}
示例#4
0
文件: slots.c 项目: daholland/wren
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);
}
示例#5
0
文件: io.c 项目: graphitemaster/wren
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);
}