Exemple #1
0
static void ensureOutsideForeign(WrenVM* vm)
{
  // To test the behavior outside of a foreign method (which we're currently
  // in), create a new separate VM.
  WrenConfiguration config;
  wrenInitConfiguration(&config);
  WrenVM* otherVM = wrenNewVM(&config);

  int before = wrenGetSlotCount(otherVM);

  wrenEnsureSlots(otherVM, 20);

  int after = wrenGetSlotCount(otherVM);

  // Use the slots to make sure they're available.
  for (int i = 0; i < 20; i++)
  {
    wrenSetSlotDouble(otherVM, i, i);
  }

  int sum = 0;

  for (int i = 0; i < 20; i++)
  {
    sum += (int)wrenGetSlotDouble(otherVM, i);
  }

  wrenFreeVM(otherVM);

  char result[100];
  sprintf(result, "%d -> %d (%d)", before, after, sum);
  wrenSetSlotString(vm, 0, result);
}
Exemple #2
0
Wren::Wren()
:   vm_( nullptr ),
    foreignMethods_() {
    
    WrenConfiguration configuration{};
    wrenInitConfiguration( &configuration );
    configuration.bindForeignMethodFn = ForeignMethodProvider;
    configuration.loadModuleFn = LoadModuleFnWrapper;
    configuration.bindForeignClassFn = ForeignClassProvider;
    configuration.writeFn = WriteFnWrapper;
    vm_ = wrenNewVM( &configuration );
}
Exemple #3
0
Fichier : vm.c Projet : 0x73/wren
static void initVM()
{
  WrenConfiguration config;
  wrenInitConfiguration(&config);

  config.bindForeignMethodFn = bindForeignMethod;
  config.bindForeignClassFn = bindForeignClass;
  config.loadModuleFn = readModule;
  config.writeFn = write;

  // Since we're running in a standalone process, be generous with memory.
  config.initialHeapSize = 1024 * 1024 * 100;
  vm = wrenNewVM(&config);

  // Initialize the event loop.
  loop = (uv_loop_t*)malloc(sizeof(uv_loop_t));
  uv_loop_init(loop);
}
Exemple #4
0
int main(int argc, char *argv[])
{
    const char* s = argc > 1 ? argv[1] : DEFAULT_SCRIPT;
    const int c = argc > 2 ? atoi(argv[2]) : DEFAULT_COUNT;
    
    count += c;
    
    char* script = readFile(s);
    if (script == NULL)
    {
        fprintf(stderr, "Could not locate %s\n", s);
        return 1;
    }
    
    WrenConfiguration config;
    wrenInitConfiguration(&config);

    config.bindForeignMethodFn = bindForeignMethod;
    //config.bindForeignClassFn = bindForeignClass;
    //config.loadModuleFn = readModule;
    config.writeFn = write;
    config.errorFn = reportError;

    // Since we're running in a standalone process, be generous with memory.
    config.initialHeapSize = 1024 * 1024 * 100;
    WrenVM* vm = wrenNewVM(&config);
    
    //fprintf(stdout, "Found hello.wren\n%s\n", script);
    
    WrenInterpretResult result = wrenInterpret(vm, script);
    if (result == WREN_RESULT_SUCCESS)
    {
        printf("%lld\n", ts_stop - ts_start);
    }
    else
    {
        fprintf(stderr, "Error executing hello.wren %d\n", result);
    }
        
    wrenFreeVM(vm);
    free(script);
    
    return result;
}