Пример #1
0
struct RProc *mrbb_proc_new(mrb_state* mrb, mrb_func_t cfunc)
{
  struct RProc *p = mrb_proc_new_cfunc(mrb, cfunc);

  p->flags |= MRB_PROC_MRBCFUNC;

  return p;
}
Пример #2
0
struct RProc *
mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals)
{
  struct RProc *p = mrb_proc_new_cfunc(mrb, func);

  closure_setup(mrb, p, nlocals);
  return p;
}
Пример #3
0
void
mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, int aspec)
{
  struct RProc *p;

  p = mrb_proc_new_cfunc(mrb, func);
  p->target_class = c;
  mrb_define_method_raw(mrb, c, mid, p);
}
Пример #4
0
static struct RProc *
method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
{
  mrb_method_t m = mrb_method_search_vm(mrb, cp, mid);
  if (MRB_METHOD_UNDEF_P(m))
    return NULL;
  if (MRB_METHOD_PROC_P(m))
    return MRB_METHOD_PROC(m);
  return mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m));
}
Пример #5
0
void
mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec)
{
  struct RProc *p;
  int ai = mrb_gc_arena_save(mrb);

  p = mrb_proc_new_cfunc(mrb, func);
  p->target_class = c;
  mrb_define_method_raw(mrb, c, mid, p);
  mrb_gc_arena_restore(mrb, ai);
}
Пример #6
0
Файл: proc.c Проект: kmasa/mruby
struct RProc *
mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t f, mrb_int argc, const mrb_value *argv)
{
    struct RProc *p;
    struct REnv *e;
    int ai, i;

    p = mrb_proc_new_cfunc(mrb, f);
    ai = mrb_gc_arena_save(mrb);
    e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, NULL);
    p->env = e;
    mrb_gc_arena_restore(mrb, ai);

    MRB_ENV_UNSHARE_STACK(e);
    MRB_ENV_STACK_LEN(e) = argc;
    e->stack = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value) * argc);
    for (i = 0; i < argc; ++i) {
        e->stack[i] = argv[i];
    }

    return p;
}
Пример #7
0
MRB_API struct RProc *
mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t func, mrb_int argc, const mrb_value *argv)
{
  struct RProc *p = mrb_proc_new_cfunc(mrb, func);
  struct REnv *e;
  int i;

  p->env = e = env_new(mrb, argc);
  MRB_ENV_UNSHARE_STACK(e);
  e->stack = (mrb_value*)mrb_malloc(mrb, sizeof(mrb_value) * argc);
  if (argv) {
    for (i = 0; i < argc; ++i) {
      e->stack[i] = argv[i];
    }
  }
  else {
    for (i = 0; i < argc; ++i) {
      SET_NIL_VALUE(e->stack[i]);
    }
  }
  return p;
}
Пример #8
0
void mrb_mruby_uv_gem_test(mrb_state* mrb) {
  mrb_define_method(mrb, mrb->object_class, "raise_signal", raise_signal, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, mrb->kernel_module, "get_work_result", get_work_result, MRB_ARGS_NONE());
  mrb_define_const(mrb, mrb->object_class, "WorkCFunc", mrb_obj_value(mrb_proc_new_cfunc(mrb, work_cfunc)));
}