Beispiel #1
0
static void startSize(WrenVM* vm)
{
  const char* path = wrenGetArgumentString(vm, 1);
  WrenValue* fiber = wrenGetArgumentValue(vm, 2);

  // Store the fiber to resume when the request completes.
  uv_fs_t* request = (uv_fs_t*)malloc(sizeof(uv_fs_t));
  request->data = fiber;

  uv_fs_stat(getLoop(), request, path, sizeCallback);
}
Beispiel #2
0
void metaCompile(WrenVM* vm)
{
  // Evaluate the code in the module where the calling function was defined.
  // That's one stack frame back from the top since the top-most frame is the
  // helper eval() method in Meta itself.
  Value callingFn = OBJ_VAL(vm->fiber->frames[vm->fiber->numFrames - 2].fn);
  ObjModule* module = IS_FN(callingFn)
      ? AS_FN(callingFn)->module
      : AS_CLOSURE(callingFn)->fn->module;

  // Compile it.
  ObjFn* fn = wrenCompile(vm, module, wrenGetArgumentString(vm, 1), false);
  if (fn == NULL) return;

  // Return the result. We can't use the public API for this since we have a
  // bare ObjFn.
  *vm->foreignCallSlot = OBJ_VAL(fn);
  vm->foreignCallSlot = NULL;
}