예제 #1
0
void
mrb_init_uefi_pointer(mrb_state *mrb, struct RClass *mrb_uefi)
{
    struct RClass *p_cls;

    p_cls = mrb_define_class_under(mrb, mrb_uefi, "Pointer", mrb->object_class);
    MRB_SET_INSTANCE_TT(p_cls, MRB_TT_DATA);

    mrb_include_module(mrb, p_cls, mrb_class_get(mrb, "Comparable"));

    mrb_define_method(mrb, p_cls, "initialize", mrb_uefi_pointer_initialize, ARGS_ANY());
    mrb_define_method(mrb, p_cls, "initialize_copy", mrb_uefi_pointer_initialize_copy, ARGS_REQ(1));
    mrb_define_method(mrb, p_cls, "<=>", mrb_uefi_pointer_cmp, ARGS_REQ(1));
    mrb_define_method(mrb, p_cls, "to_s", mrb_uefi_pointer_to_s, ARGS_NONE());
    mrb_define_method(mrb, p_cls, "inspect", mrb_uefi_pointer_inspect, ARGS_NONE());
    mrb_define_method(mrb, p_cls, "value", mrb_uefi_pointer_value, ARGS_NONE());
    mrb_define_method(mrb, p_cls, "to_i", mrb_uefi_pointer_to_i, ARGS_NONE());
    mrb_define_method(mrb, p_cls, "+", mrb_uefi_pointer_plus, ARGS_REQ(1));
    mrb_define_method(mrb, p_cls, "-", mrb_uefi_pointer_minus, ARGS_REQ(1));
    mrb_define_method(mrb, p_cls, "read", mrb_uefi_pointer_read, ARGS_REQ(1));
    mrb_define_method(mrb, p_cls, "write", mrb_uefi_pointer_write, ARGS_REQ(1));

    mrb_const_set(mrb, mrb_obj_value(p_cls), mrb_intern(mrb, "NULL"),
                  mrb_uefi_pointer_make_helper(mrb, p_cls, NULL));
}
예제 #2
0
파일: object.c 프로젝트: flexfrank/mruby
void
mrb_init_object(mrb_state *mrb)
{
  struct RClass *n;
  struct RClass *t;
  struct RClass *f;

  n = mrb->nil_class   = mrb_define_class(mrb, "NilClass",   mrb->object_class);
  mrb_define_method(mrb, n, "&",    false_and,      ARGS_REQ(1));  /* 15.2.4.3.1  */
  mrb_define_method(mrb, n, "^",    false_xor,      ARGS_REQ(1));  /* 15.2.4.3.2  */
  mrb_define_method(mrb, n, "|",    false_or,       ARGS_REQ(1));  /* 15.2.4.3.3  */
  mrb_define_method(mrb, n, "nil?", mrb_true,       ARGS_NONE());  /* 15.2.4.3.4  */
  mrb_define_method(mrb, n, "to_s", nil_to_s,       ARGS_NONE());  /* 15.2.4.3.5  */

  t = mrb->true_class  = mrb_define_class(mrb, "TrueClass",  mrb->object_class);
  mrb_define_method(mrb, t, "&",    true_and,       ARGS_REQ(1));  /* 15.2.5.3.1  */
  mrb_define_method(mrb, t, "^",    true_xor,       ARGS_REQ(1));  /* 15.2.5.3.2  */
  mrb_define_method(mrb, t, "to_s", true_to_s,      ARGS_NONE());  /* 15.2.5.3.3  */
  mrb_define_method(mrb, t, "|",    true_or,        ARGS_REQ(1));  /* 15.2.5.3.4  */

  f = mrb->false_class = mrb_define_class(mrb, "FalseClass", mrb->object_class);
  mrb_define_method(mrb, f, "&",    false_and,      ARGS_REQ(1));  /* 15.2.6.3.1  */
  mrb_define_method(mrb, f, "^",    false_xor,      ARGS_REQ(1));  /* 15.2.6.3.2  */
  mrb_define_method(mrb, f, "to_s", false_to_s,     ARGS_NONE());  /* 15.2.6.3.3  */
  mrb_define_method(mrb, f, "|",    false_or,       ARGS_REQ(1));  /* 15.2.6.3.4  */
}
예제 #3
0
파일: pcap.c 프로젝트: selman/mruby-pcap
void
mrb_mruby_pcap_gem_init(mrb_state *mrb)
{
  struct RClass *pcap, *capt;

  pcap = mrb_define_module(mrb, "Pcap");
  mrb_define_module_function(mrb, pcap, "lookupdev", mrb_pcap_s_lookupdev, ARGS_NONE());
  mrb_define_module_function(mrb, pcap, "lookupnet", pcap_s_lookupnet,
                             ARGS_REQ(1));

  mrb_define_const(mrb, pcap, "DLT_NULL", mrb_fixnum_value(DLT_NULL));
  mrb_define_const(mrb, pcap, "DLT_EN10MB", mrb_fixnum_value(DLT_EN10MB));
  mrb_define_const(mrb, pcap, "DLT_PPP", mrb_fixnum_value(DLT_PPP));
#ifdef DLT_RAW
  mrb_define_const(mrb, pcap, "DLT_RAW", mrb_fixnum_value(DLT_RAW));
#endif

  capt = mrb_define_class_under(mrb, pcap, "Capture", mrb->object_class);
  mrb_define_singleton_method(mrb, (struct RObject*)capt, "open_live", mrb_capture_open_live, MRB_ARGS_ARG(1, 3));
  mrb_define_method(mrb, capt, "capture", capture, ARGS_NONE());
  mrb_define_method(mrb, capt, "close", capture_close, ARGS_NONE());
  mrb_define_method(mrb, capt, "datalink", capture_datalink, ARGS_NONE());
  mrb_define_method(mrb, capt, "inject", mrb_capture_inject, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, capt, "setfilter", capture_setfilter, ARGS_ANY());
}
예제 #4
0
파일: io.c 프로젝트: Epictetus/mruby-io
void
mrb_init_io(mrb_state *mrb)
{
  struct RClass *io;

  io      = mrb_define_class(mrb, "IO", mrb->object_class);
  MRB_SET_INSTANCE_TT(io, MRB_TT_DATA);

  mrb_include_module(mrb, io, mrb_class_get(mrb, "Enumerable")); /* 15.2.20.3 */

  mrb_define_class_method(mrb, io, "_popen",  mrb_io_s_popen,   ARGS_ANY());
  mrb_define_class_method(mrb, io, "for_fd",  mrb_io_s_for_fd,  ARGS_REQ(1)|ARGS_OPT(2));
  mrb_define_class_method(mrb, io, "sysopen", mrb_io_s_sysopen, ARGS_ANY());

  mrb_define_method(mrb, io, "_bless",     mrb_io_bless,       ARGS_NONE());
  mrb_define_method(mrb, io, "initialize", mrb_io_initialize,  ARGS_ANY());    /* 15.2.20.5.21 (x)*/
  mrb_define_method(mrb, io, "sysread",    mrb_io_sysread,     ARGS_ANY());
  mrb_define_method(mrb, io, "sysseek",    mrb_io_sysseek,     ARGS_REQ(1));
  mrb_define_method(mrb, io, "syswrite",   mrb_io_syswrite,    ARGS_REQ(1));
  mrb_define_method(mrb, io, "close",      mrb_io_close,       ARGS_NONE());   /* 15.2.20.5.1 */
  mrb_define_method(mrb, io, "closed?",    mrb_io_closed,      ARGS_NONE());   /* 15.2.20.5.2 */
  mrb_define_method(mrb, io, "pid",        mrb_io_pid,         ARGS_NONE());   /* 15.2.20.5.2 */
  mrb_define_method(mrb, io, "fileno",     mrb_io_fileno,      ARGS_NONE());

  mrb_gv_set(mrb, mrb_intern(mrb, "$/"), mrb_str_new_cstr(mrb, "\n"));
}
예제 #5
0
파일: proc.c 프로젝트: Hozum/mruby
void
mrb_init_proc(mrb_state *mrb)
{
  struct RProc *m;
  mrb_irep *call_irep = (mrb_irep *)mrb_alloca(mrb, sizeof(mrb_irep));
  static const mrb_irep mrb_irep_zero = { 0 };

  if ( call_iseq == NULL || call_irep == NULL )
    return;

  *call_irep = mrb_irep_zero;
  call_irep->flags = MRB_ISEQ_NO_FREE;
  call_irep->idx = -1;
  call_irep->iseq = call_iseq;
  call_irep->ilen = 1;

  mrb->proc_class = mrb_define_class(mrb, "Proc", mrb->object_class);
  MRB_SET_INSTANCE_TT(mrb->proc_class, MRB_TT_PROC);

  mrb_define_method(mrb, mrb->proc_class, "initialize", mrb_proc_initialize, ARGS_NONE());
  mrb_define_method(mrb, mrb->proc_class, "initialize_copy", mrb_proc_init_copy, ARGS_REQ(1));

  m = mrb_proc_new(mrb, call_irep);
  mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "call"), m);
  mrb_define_method_raw(mrb, mrb->proc_class, mrb_intern(mrb, "[]"), m);

  mrb_define_class_method(mrb, mrb->kernel_module, "lambda", proc_lambda, ARGS_NONE());    /* 15.3.1.2.6  */
  mrb_define_method(mrb, mrb->kernel_module,       "lambda", proc_lambda, ARGS_NONE());    /* 15.3.1.3.27 */
}
예제 #6
0
void
mrb_mruby_fake_gem_gem_init(mrb_state* mrb) {

  struct RClass *fakeClass = mrb_define_class(mrb, "Fake", mrb->object_class);
  mrb_define_method(mrb, fakeClass, "c_method1", fake_c_method1, ARGS_NONE());
  mrb_define_method(mrb, fakeClass, "c_method2", fake_c_method2, ARGS_NONE());
}
예제 #7
0
void init_cfunc_platform(mrb_state *mrb, struct RClass* module)
{
    struct RClass *struct_class = mrb_define_class_under(mrb, module, "Platform", mrb->object_class);
    
    mrb_define_class_method(mrb, struct_class, "is_posix?", cfunc_platform_is_posix, ARGS_NONE());
    mrb_define_class_method(mrb, struct_class, "is_win32?", cfunc_platform_is_win32, ARGS_NONE());
    mrb_define_class_method(mrb, struct_class, "is_darwin?", cfunc_platform_is_darwin, ARGS_NONE());
}
예제 #8
0
void
qgame_texture_asset_init(mrb_state* mrb, struct RClass* mrb_qgame_class) {
  struct RClass *texture_asset_class = mrb_define_class_under(mrb, mrb_qgame_class, 
    "TextureAsset", mrb->object_class);

  mrb_define_method(mrb, texture_asset_class, "load_from_file", qgame_texture_asset_load_from_file, ARGS_REQ(1));
  mrb_define_method(mrb, texture_asset_class, "bind", qgame_texture_asset_bind, ARGS_NONE());
  mrb_define_method(mrb, texture_asset_class, "unbind", qgame_texture_asset_unbind, ARGS_NONE());
}
예제 #9
0
파일: error.c 프로젝트: andych008/mruby
void
mrb_init_exception(mrb_state *mrb)
{
  struct RClass *e;
  struct RClass *eTypeError_class;
  struct RClass *eArgumentError_class;
  struct RClass *eIndexError_class;
  struct RClass *eRangeError_class;
  struct RClass *eNameError_class;
  struct RClass *eNoMethodError_class;
  struct RClass *eScriptError_class;
  struct RClass *eSyntaxError_class;
  struct RClass *eLoadError_class;
  struct RClass *eSystemCallError_class;
  struct RClass *eLocalJumpError_class;
  struct RClass *eRegexpError_class;
  struct RClass *eZeroDivisionError_class;
  struct RClass *eEncodingError_class;
  struct RClass *eNotImpError_class;
  struct RClass *eFloatDomainError_class;
  struct RClass *eKeyError_class;

  mrb->eException_class = e = mrb_define_class(mrb, "Exception",           mrb->object_class);         /* 15.2.22 */
  mrb_define_class_method(mrb, e, "exception", mrb_instance_new, ARGS_ANY());
  mrb_define_method(mrb, e, "exception", exc_exception, ARGS_ANY());
  mrb_define_method(mrb, e, "initialize", exc_initialize, ARGS_ANY());
  mrb_define_method(mrb, e, "==", exc_equal, ARGS_REQ(1));
  mrb_define_method(mrb, e, "to_s", exc_to_s, ARGS_NONE());
  mrb_define_method(mrb, e, "message", exc_message, ARGS_NONE());
  mrb_define_method(mrb, e, "inspect", exc_inspect, ARGS_NONE());

  mrb->eStandardError_class     = mrb_define_class(mrb, "StandardError",       mrb->eException_class);     /* 15.2.23 */
  mrb->eRuntimeError_class      = mrb_define_class(mrb, "RuntimeError",        mrb->eStandardError_class); /* 15.2.28 */

  eTypeError_class              = mrb_define_class(mrb, "TypeError",           mrb->eStandardError_class); /* 15.2.29 */
  eArgumentError_class          = mrb_define_class(mrb, "ArgumentError",       mrb->eStandardError_class); /* 15.2.24 */
  eIndexError_class             = mrb_define_class(mrb, "IndexError",          mrb->eStandardError_class); /* 15.2.33 */
  eRangeError_class             = mrb_define_class(mrb, "RangeError",          mrb->eStandardError_class); /* 15.2.26 */
  eNameError_class              = mrb_define_class(mrb, "NameError",           mrb->eStandardError_class); /* 15.2.31 */

  eNoMethodError_class          = mrb_define_class(mrb, "NoMethodError",       eNameError_class);          /* 15.2.32 */
  eScriptError_class            = mrb_define_class(mrb, "ScriptError",         mrb->eException_class);     /* 15.2.37 */
  eSyntaxError_class            = mrb_define_class(mrb, "SyntaxError",         eScriptError_class);        /* 15.2.38 */
  eLoadError_class              = mrb_define_class(mrb, "LoadError",           eScriptError_class);        /* 15.2.39 */
  eSystemCallError_class        = mrb_define_class(mrb, "SystemCallError",     mrb->eStandardError_class); /* 15.2.36 */
  eLocalJumpError_class         = mrb_define_class(mrb, "LocalJumpError",      mrb->eStandardError_class); /* 15.2.25 */
  eRegexpError_class            = mrb_define_class(mrb, "RegexpError",         mrb->eStandardError_class); /* 15.2.27 */
  eZeroDivisionError_class      = mrb_define_class(mrb, "ZeroDivisionError",   mrb->eStandardError_class); /* 15.2.30 */

  eEncodingError_class          = mrb_define_class(mrb, "EncodingError",       mrb->eStandardError_class);
  eNotImpError_class            = mrb_define_class(mrb, "NotImplementedError", eScriptError_class);

  eFloatDomainError_class       = mrb_define_class(mrb, "FloatDomainError",    eRangeError_class);
  eKeyError_class               = mrb_define_class(mrb, "KeyError",            eIndexError_class);
}
예제 #10
0
파일: class.c 프로젝트: gitpan/mRuby
void
mrb_init_class(mrb_state *mrb)
{
  struct RClass *bob;           /* BasicObject */
  struct RClass *obj;           /* Object */
  struct RClass *mod;           /* Module */
  struct RClass *cls;           /* Class */
  //struct RClass *krn;    /* Kernel */

  /* boot class hierarchy */
  bob = boot_defclass(mrb, 0);
  obj = boot_defclass(mrb, bob); mrb->object_class = obj;
  mod = boot_defclass(mrb, obj); mrb->module_class = mod;/* obj -> mod */
  cls = boot_defclass(mrb, mod); mrb->class_class = cls; /* obj -> cls */
  /* fix-up loose ends */
  bob->c = obj->c = mod->c = cls->c = cls;
  make_metaclass(mrb, bob);
  make_metaclass(mrb, obj);
  make_metaclass(mrb, mod);
  make_metaclass(mrb, cls);

  /* name basic classes */
  mrb_define_const(mrb, obj, "BasicObject", mrb_obj_value(bob));
  mrb_define_const(mrb, obj, "Object", mrb_obj_value(obj));
  mrb_define_const(mrb, obj, "Module", mrb_obj_value(mod));
  mrb_define_const(mrb, obj, "Class", mrb_obj_value(cls));

  /* name each classes */
  mrb_name_class(mrb, bob, mrb_intern(mrb, "BasicObject"));
  mrb_name_class(mrb, obj, mrb_intern(mrb, "Object"));
  mrb_name_class(mrb, mod, mrb_intern(mrb, "Module"));
  mrb_name_class(mrb, cls, mrb_intern(mrb, "Class"));

  mrb_undef_method(mrb, mod, "new");
  MRB_SET_INSTANCE_TT(cls, MRB_TT_CLASS);
  mrb_define_method(mrb, bob, "initialize", mrb_bob_init, ARGS_NONE());
  mrb_define_method(mrb, bob, "!", mrb_bob_not, ARGS_NONE());
  mrb_define_method(mrb, bob, "method_missing", mrb_bob_missing, ARGS_ANY());        /* 15.3.1.3.30 */
  mrb_define_class_method(mrb, cls, "new", mrb_class_new_class, ARGS_ANY());
  mrb_define_method(mrb, cls, "superclass", mrb_class_superclass, ARGS_NONE());      /* 15.2.3.3.4 */
  mrb_define_method(mrb, cls, "new", mrb_instance_new, ARGS_ANY());                  /* 15.2.3.3.3 */
  mrb_define_method(mrb, cls, "inherited", mrb_bob_init, ARGS_REQ(1));
  mrb_define_method(mrb, mod, "include", mrb_mod_include, ARGS_REQ(1));              /* 15.2.2.4.27 */

  mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE());
  mrb_define_method(mrb, mod, "alias_method", mrb_mod_alias, ARGS_ANY());            /* 15.2.2.4.8 */
  mrb_define_method(mrb, mod, "undef_method", mrb_mod_undef, ARGS_ANY());            /* 15.2.2.4.41 */
  mrb_define_method(mrb, mod, "const_defined?", mrb_mod_const_defined, ARGS_REQ(1)); /* 15.2.2.4.20 */
  mrb_define_method(mrb, mod, "const_get", mrb_mod_const_get, ARGS_REQ(1));          /* 15.2.2.4.21 */
  mrb_define_method(mrb, mod, "const_set", mrb_mod_const_set, ARGS_REQ(2));          /* 15.2.2.4.23 */
  mrb_define_method(mrb, mod, "define_method", mod_define_method, ARGS_REQ(1));

  mrb_define_method(mrb, mod, "===", mrb_mod_eqq, ARGS_REQ(1));
}
예제 #11
0
파일: struct.c 프로젝트: akuroda/mruby
static mrb_value
make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * klass)
{
    mrb_value nstr, *ptr_members;
    mrb_sym id;
    long i, len;
    struct RClass *c;

    //OBJ_FREEZE(members);
    if (mrb_nil_p(name)) {
      c = mrb_class_new(mrb, klass);
      //mrb_make_metaclass(nstr, RBASIC(klass)->c);
      //mrb_class_inherited(klass, nstr);
    }
    else {
      /* old style: should we warn? */
      name = mrb_str_to_str(mrb, name);
      id = mrb_to_id(mrb, name);
      if (!mrb_is_const_id(id)) {
          //mrb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name));
          mrb_name_error(mrb, id, "identifier %s needs to be constant", mrb_string_value_ptr(mrb, name));
      }
      if (mrb_const_defined_at(mrb, klass, id)) {
          //mrb_warn("redefining constant Struct::%s", StringValuePtr(name));
          mrb_warn("redefining constant Struct::%s", mrb_string_value_ptr(mrb, name));
          //?rb_mod_remove_const(klass, mrb_sym2name(mrb, id));
      }
      c = mrb_define_class_under(mrb, klass, RSTRING_PTR(name), klass);
    }
    MRB_SET_INSTANCE_TT(c, MRB_TT_STRUCT);
    nstr = mrb_obj_value(c);
    mrb_iv_set(mrb, nstr, mrb_intern(mrb, "__members__"), members);

    mrb_define_class_method(mrb, c, "new", mrb_instance_new, ARGS_ANY());
    mrb_define_class_method(mrb, c, "[]", mrb_instance_new, ARGS_ANY());
    mrb_define_class_method(mrb, c, "members", mrb_struct_s_members_m, ARGS_NONE());
    //RSTRUCT(nstr)->basic.c->super = c->c;
    ptr_members = RARRAY_PTR(members);
    len = RARRAY_LEN(members);
    for (i=0; i< len; i++) {
      mrb_sym id = SYM2ID(ptr_members[i]);
      if (mrb_is_local_id(id) || mrb_is_const_id(id)) {
          if (i < N_REF_FUNC) {
            mrb_define_method_id(mrb, c, id, ref_func[i], ARGS_NONE());
          }
          else {
            mrb_define_method_id(mrb, c, id, mrb_struct_ref, ARGS_NONE());
          }
          mrb_define_method_id(mrb, c, mrb_id_attrset(mrb, id), mrb_struct_set_m, ARGS_REQ(1));
      }
    }

    return nstr;
}
예제 #12
0
void ap_mruby_env_init(mrb_state *mrb, struct RClass *class_core)
{
  struct RClass *class_env;

  int ai = mrb_gc_arena_save(mrb);
  class_env = mrb_define_class_under(mrb, class_core, "Env", mrb->object_class);
  mrb_define_method(mrb, class_env, "initialize", ap_mrb_init_env, ARGS_NONE());
  mrb_define_method(mrb, class_env, "[]=", ap_mrb_set_env, ARGS_ANY());
  mrb_define_method(mrb, class_env, "[]", ap_mrb_get_env, ARGS_ANY());
  mrb_define_method(mrb, class_env, "all", ap_mrb_get_env_hash, ARGS_NONE());
  mrb_gc_arena_restore(mrb, ai);
}
예제 #13
0
파일: gc.c 프로젝트: guanqun/mruby
void
mrb_init_gc(mrb_state *mrb)
{
  struct RClass *gc;
  gc = mrb_define_module(mrb, "GC");

  mrb_define_class_method(mrb, gc, "start", gc_start, ARGS_NONE());
  mrb_define_class_method(mrb, gc, "interval_ratio", gc_interval_ratio_get, ARGS_NONE());
  mrb_define_class_method(mrb, gc, "interval_ratio=", gc_interval_ratio_set, ARGS_REQ(1));
  mrb_define_class_method(mrb, gc, "step_ratio", gc_step_ratio_get, ARGS_NONE());
  mrb_define_class_method(mrb, gc, "step_ratio=", gc_step_ratio_set, ARGS_REQ(1));
}
예제 #14
0
void
mrb_mruby_rx_gpio_gem_init(mrb_state* mrb) {


    struct RClass *gpio;
    gpio = mrb_define_class(mrb, "Rx_gpio", mrb->object_class);

    mrb_define_const(mrb,gpio, "LED0", mrb_fixnum_value(100));
    mrb_define_const(mrb,gpio, "LED1", mrb_fixnum_value(101));
    mrb_define_const(mrb,gpio, "LED2", mrb_fixnum_value(102));
    mrb_define_const(mrb,gpio, "LED3", mrb_fixnum_value(103));

    mrb_define_const(mrb,gpio, "IO2", mrb_fixnum_value(202));
    mrb_define_const(mrb,gpio, "IO3", mrb_fixnum_value(203));
    mrb_define_const(mrb,gpio, "IO4", mrb_fixnum_value(204));
    mrb_define_const(mrb,gpio, "IO5", mrb_fixnum_value(205));

    mrb_define_const(mrb,gpio, "IO44", mrb_fixnum_value(210));
    mrb_define_const(mrb,gpio, "IO45", mrb_fixnum_value(211));
    mrb_define_const(mrb,gpio, "IO46", mrb_fixnum_value(212));
    mrb_define_const(mrb,gpio, "IO47", mrb_fixnum_value(213));
    mrb_define_const(mrb,gpio, "IO48", mrb_fixnum_value(214));
    mrb_define_const(mrb,gpio, "IO49", mrb_fixnum_value(215));
    mrb_define_const(mrb,gpio, "IO50", mrb_fixnum_value(216));
    mrb_define_const(mrb,gpio, "IO51", mrb_fixnum_value(217));

    mrb_define_const(mrb,gpio, "IO11", mrb_fixnum_value(249));
    mrb_define_const(mrb,gpio, "IO12", mrb_fixnum_value(250));


    mrb_define_const(mrb,gpio, "IO2IN", mrb_fixnum_value(302));
    mrb_define_const(mrb,gpio, "IO3IN", mrb_fixnum_value(303));
    mrb_define_const(mrb,gpio, "IO4IN", mrb_fixnum_value(304));
    mrb_define_const(mrb,gpio, "IO5IN", mrb_fixnum_value(305));

    mrb_define_const(mrb,gpio, "IO44IN", mrb_fixnum_value(310));
    mrb_define_const(mrb,gpio, "IO45IN", mrb_fixnum_value(311));
    mrb_define_const(mrb,gpio, "IO46IN", mrb_fixnum_value(312));
    mrb_define_const(mrb,gpio, "IO47IN", mrb_fixnum_value(313));
    mrb_define_const(mrb,gpio, "IO48IN", mrb_fixnum_value(314));
    mrb_define_const(mrb,gpio, "IO49IN", mrb_fixnum_value(315));
    mrb_define_const(mrb,gpio, "IO50IN", mrb_fixnum_value(316));
    mrb_define_const(mrb,gpio, "IO51IN", mrb_fixnum_value(317));
    mrb_define_const(mrb,gpio, "IO12IN", mrb_fixnum_value(350));

    /* methods */
    mrb_define_method(mrb, gpio, "initialize", mrb_rx_gpio_initialize, ARGS_REQ(1));
    mrb_define_method(mrb, gpio, "on", mrb_rx_gpio_on, ARGS_NONE());
    mrb_define_method(mrb, gpio, "off", mrb_rx_gpio_off, ARGS_NONE());
    mrb_define_method(mrb, gpio, "in", mrb_rx_gpio_input, ARGS_NONE());

}
예제 #15
0
void
mrb_mruby_ssp_thread_gem_init(mrb_state* mrb) {


	struct RClass *ssp;
	ssp = mrb_define_class(mrb, "Ssp_thread", mrb->object_class);

	/* methods */
	mrb_define_method(mrb, ssp, "initialize", mrb_ssp_thread_initialize, ARGS_REQ(2));
	mrb_define_method(mrb, ssp, "act" , mrb_ssp_thread_act, ARGS_NONE());
	mrb_define_method(mrb, ssp, "iact", mrb_ssp_thread_iact, ARGS_NONE());

}
예제 #16
0
void
mrb_mruby_ssp_cyclic_gem_init(mrb_state* mrb) {


	struct RClass *cyc;
	cyc = mrb_define_class(mrb, "Ssp_cyclic", mrb->object_class);

	/* methods */
	mrb_define_method(mrb, cyc, "initialize", mrb_ssp_cyclic_initialize, ARGS_REQ(2));
	mrb_define_method(mrb, cyc, "start", mrb_ssp_cyclic_sta, ARGS_NONE());
	mrb_define_method(mrb, cyc, "stop" , mrb_ssp_cyclic_stp, ARGS_NONE());
	mrb_define_method(mrb, cyc, "istop" , mrb_ssp_cyclic_istp, ARGS_NONE());

}
예제 #17
0
void
mrb_init_symbols(mrb_state *mrb)
{
  struct RClass *sym;

  sym = mrb->symbol_class = mrb_define_class(mrb, "Symbol", mrb->object_class);

  mrb_define_method(mrb, sym, "===",             sym_equal,               ARGS_REQ(1));              /* 15.2.11.3.1  */
  mrb_define_method(mrb, sym, "id2name",         mrb_sym_to_s,            ARGS_NONE());              /* 15.2.11.3.2  */
  mrb_define_method(mrb, sym, "to_s",            mrb_sym_to_s,            ARGS_NONE());              /* 15.2.11.3.3  */
  mrb_define_method(mrb, sym, "to_sym",          sym_to_sym,              ARGS_NONE());              /* 15.2.11.3.4  */

  mrb_define_method(mrb, sym, "inspect",         sym_inspect,             ARGS_NONE());              /* 15.2.11.3.5(x)  */
}
예제 #18
0
파일: range.c 프로젝트: guanqun/mruby
void
mrb_init_range(mrb_state *mrb)
{
  struct RClass *r;

  r = mrb_define_class(mrb, "Range", mrb->object_class);
  mrb_include_module(mrb, r, mrb_class_get(mrb, "Enumerable"));

  mrb_define_method(mrb, r, "begin",           mrb_range_beg,         ARGS_NONE());      /* 15.2.14.4.3  */
  mrb_define_method(mrb, r, "end",             mrb_range_end,         ARGS_NONE());      /* 15.2.14.4.5  */
  mrb_define_method(mrb, r, "==",              mrb_range_eq,          ARGS_REQ(1));      /* 15.2.14.4.1  */
  mrb_define_method(mrb, r, "===",             mrb_range_include,     ARGS_REQ(1));      /* 15.2.14.4.2  */
  mrb_define_method(mrb, r, "each",            mrb_range_each,        ARGS_NONE());      /* 15.2.14.4.4  */
  mrb_define_method(mrb, r, "exclude_end?",    mrb_range_excl,        ARGS_NONE());      /* 15.2.14.4.6  */
  mrb_define_method(mrb, r, "first",           mrb_range_beg,         ARGS_NONE());      /* 15.2.14.4.7  */
  mrb_define_method(mrb, r, "include?",        mrb_range_include,     ARGS_REQ(1));      /* 15.2.14.4.8  */
  mrb_define_method(mrb, r, "initialize",      mrb_range_initialize,  ARGS_REQ(4));      /* 15.2.14.4.9  */
  mrb_define_method(mrb, r, "last",            mrb_range_end,         ARGS_NONE());      /* 15.2.14.4.10 */
  mrb_define_method(mrb, r, "member?",         mrb_range_include,     ARGS_REQ(1));      /* 15.2.14.4.11 */

  mrb_define_method(mrb, r, "to_s",            range_to_s,            ARGS_NONE());      /* 15.2.14.4.12(x) */
  mrb_define_method(mrb, r, "inspect",         range_inspect,         ARGS_NONE());      /* 15.2.14.4.13(x) */
  mrb_define_method(mrb, r, "eql?",            range_eql,             ARGS_REQ(1));      /* 15.2.14.4.14(x) */
  mrb_define_method(mrb, r, "initialize_copy", range_initialize_copy, ARGS_REQ(1));      /* 15.2.14.4.15(x) */
}
static int ap_mruby_class_init(mrb_state *mrb)
{
    struct RClass *class;
    struct RClass *class_manager;

    class = mrb_define_module(mrb, "Resource");
    class_manager = mrb_define_class_under(mrb, class, "Manager", mrb->object_class);
    mrb_define_method(mrb, class_manager, "cpurate=", ap_mrb_set_cpurate, ARGS_ANY());
    mrb_define_method(mrb, class_manager, "cpurate", ap_mrb_get_cpurate, ARGS_NONE());
    mrb_define_method(mrb, class_manager, "filename=", ap_mrb_set_request_filename, ARGS_ANY());
    mrb_define_method(mrb, class_manager, "filename", ap_mrb_get_request_filename, ARGS_NONE());

    return OK;
}
예제 #20
0
파일: env.c 프로젝트: mattn/mruby-env
void
mrb_mruby_env_gem_init(mrb_state *mrb)
{
  struct RObject *e;

  origenviron = environ;
  e = (struct RObject*) mrb_obj_alloc(mrb, MRB_TT_OBJECT, mrb->object_class);
  mrb_include_module(mrb, (struct RClass*)e, mrb_class_get(mrb, "Enumerable"));

  mrb_define_singleton_method(mrb, e,"[]",       mrb_env_aget,       ARGS_REQ(1));
  mrb_define_singleton_method(mrb, e,"[]=",      mrb_env_aset,       ARGS_REQ(2));
  mrb_define_singleton_method(mrb, e,"store",    mrb_env_aset,       ARGS_REQ(2));
  mrb_define_singleton_method(mrb, e,"clear",    mrb_env_clear,      ARGS_NONE());
  mrb_define_singleton_method(mrb, e,"delete",   mrb_env_delete,     ARGS_REQ(1));
  mrb_define_singleton_method(mrb, e,"keys",     mrb_env_keys,       ARGS_NONE());
  mrb_define_singleton_method(mrb, e,"values",   mrb_env_values,     ARGS_NONE());
  mrb_define_singleton_method(mrb, e,"size",     mrb_env_size,       ARGS_NONE());

  mrb_define_singleton_method(mrb, e,"to_hash",  mrb_env_to_hash,    ARGS_NONE());
  mrb_define_singleton_method(mrb, e,"to_a",     mrb_env_to_a,       ARGS_NONE());
  mrb_define_singleton_method(mrb, e,"inspect",  mrb_env_inspect,    ARGS_NONE());
  mrb_define_singleton_method(mrb, e,"to_s",     mrb_env_to_s,       ARGS_NONE());

  mrb_define_global_const(mrb, "ENV", mrb_obj_value(e));
}
예제 #21
0
void
mrb_mruby_mindstorms_ev3_gem_init(mrb_state* mrb) {
  struct RClass *ev3_class = mrb_define_class(mrb, "EV3", mrb->object_class);
  mrb_define_method(mrb, ev3_class, "initialize", mrb_ev3_initialize, ARGS_NONE());
  mrb_define_method(mrb, ev3_class, "keypad?", mrb_ev3_keypad, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, ev3_class, "led=", mrb_ev3_set_led, MRB_ARGS_REQ(1));
}
예제 #22
0
void
mrb_mruby_numeric_ext_gem_init(mrb_state* mrb)
{
  struct RClass *i = mrb_class_get(mrb, "Integer");

  mrb_define_method(mrb, i, "chr",    mrb_int_chr,            ARGS_NONE());
}
예제 #23
0
void
mrb_init_uefi_handle(mrb_state *mrb, struct RClass *mrb_uefi)
{
    struct RClass *h_cls;

    h_cls = mrb_define_class_under(mrb, mrb_uefi, "Handle", mrb->object_class);
    MRB_SET_INSTANCE_TT(h_cls, MRB_TT_DATA);

    mrb_define_method(mrb, h_cls, "==", mrb_uefi_handle_eq, ARGS_REQ(1));
    mrb_define_method(mrb, h_cls, "to_s", mrb_uefi_handle_to_s, ARGS_NONE());
    mrb_define_method(mrb, h_cls, "inspect", mrb_uefi_handle_inspect, ARGS_NONE());
    mrb_define_method(mrb, h_cls, "value", mrb_uefi_handle_value, ARGS_NONE());

    mrb_const_set(mrb, mrb_obj_value(h_cls), mrb_intern(mrb, "NULL"),
                  mrb_uefi_handle_make_helper(mrb, h_cls, NULL));
}
void EXPORT
mrb_mruby_require_example_gem_init(mrb_state* mrb) {
  int ai = mrb_gc_arena_save(mrb);
  _class_example = mrb_define_module(mrb, "Example");
  mrb_define_class_method(mrb, _class_example, "helloworld", mrb_example_helloworld, ARGS_NONE());
  mrb_gc_arena_restore(mrb, ai);
}
예제 #25
0
void TRI_InitMRUtils (mrb_state* mrb) {
  MR_state_t* mrs;
  struct RClass *rcl;

  mrs = (MR_state_t*) mrb->ud;
  rcl = mrb->kernel_module;

  // .............................................................................
  // timing function
  // .............................................................................

  mrb_define_method(mrb, rcl, "time", MR_Time, ARGS_NONE());

  // .............................................................................
  // arango exception
  // .............................................................................

  mrs->_arangoError = mrb_define_class(mrb, "ArangoError", mrb->eStandardError_class);

  // .............................................................................
  // json parser and generator
  // .............................................................................

  rcl = mrb_define_class(mrb, "ArangoJson", mrb->object_class);

  mrb_define_class_method(mrb, rcl, "parse", MR_JsonParse, ARGS_REQ(1));
}
예제 #26
0
파일: sprite.c 프로젝트: mirichi/glmruby
void glmrb_sprite_init(mrb_state *mrb)
{
  cSprite = mrb_define_class(mrb, "Sprite", mrb->object_class);
  MRB_SET_INSTANCE_TT(cSprite, MRB_TT_DATA);

  mrb_define_method(mrb, cSprite, "initialize", glmrb_sprite_initialize, ARGS_REQ(3));
  mrb_define_method(mrb, cSprite, "draw", glmrb_sprite_draw, ARGS_NONE());
}
예제 #27
0
void define_digital_out(mrb_state* mrb, struct RClass* mbed_mod) {
  // creating class DigitalOut
  struct RClass *digital_out_class = mrb_define_class_under(mrb, mbed_mod, "DigitalOut", NULL);
  MRB_SET_INSTANCE_TT(digital_out_class, MRB_TT_DATA);
  mrb_define_method(mrb, digital_out_class, "initialize", mrb_digital_out_initialize, ARGS_REQ(1) | ARGS_OPT(1));
  mrb_define_method(mrb, digital_out_class, "write", mrb_digital_out_write, ARGS_REQ(1));
  mrb_define_method(mrb, digital_out_class, "read", mrb_digital_out_read, ARGS_NONE());
}
예제 #28
0
파일: string.c 프로젝트: Hozum/mruby
void
mrb_mruby_string_ext_gem_init(mrb_state* mrb)
{
  struct RClass * s = mrb->string_class;

  mrb_define_method(mrb, s, "dump",            mrb_str_dump,            ARGS_NONE());
  mrb_define_method(mrb, s, "getbyte",         mrb_str_getbyte,         ARGS_REQ(1));
}
예제 #29
0
파일: error.c 프로젝트: Blorgus/mruby
void
mrb_init_exception(mrb_state *mrb)
{
  struct RClass *e;

  mrb->eException_class = e = mrb_define_class(mrb, "Exception",           mrb->object_class);         /* 15.2.22 */
  mrb_define_class_method(mrb, e, "exception", mrb_instance_new, ARGS_ANY());
  mrb_define_method(mrb, e, "exception", exc_exception, ARGS_ANY());
  mrb_define_method(mrb, e, "initialize", exc_initialize, ARGS_ANY());
  mrb_define_method(mrb, e, "==", exc_equal, ARGS_REQ(1));
  mrb_define_method(mrb, e, "to_s", exc_to_s, ARGS_NONE());
  mrb_define_method(mrb, e, "message", exc_message, ARGS_NONE());
  mrb_define_method(mrb, e, "inspect", exc_inspect, ARGS_NONE());

  mrb->eStandardError_class     = mrb_define_class(mrb, "StandardError",       mrb->eException_class); /* 15.2.23 */
  mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class);                                    /* 15.2.28 */
}
예제 #30
0
void
mrb_mruby_process_gem_init(mrb_state *mrb)
{
  struct RClass *p;

  mrb_define_method(mrb, mrb->kernel_module, "exit", mrb_f_exit, ARGS_OPT(1));
  mrb_define_method(mrb, mrb->kernel_module, "sleep", mrb_f_sleep, ARGS_ANY());
  mrb_define_method(mrb, mrb->kernel_module, "system", mrb_f_system, ARGS_ANY());

  p = mrb_define_module(mrb, "Process");
  mrb_define_class_method(mrb, p, "kill", mrb_f_kill, ARGS_ANY());
  mrb_define_class_method(mrb, p, "fork", mrb_f_fork, ARGS_NONE());
  mrb_define_class_method(mrb, p, "waitpid", mrb_f_waitpid, ARGS_ANY());
  mrb_define_class_method(mrb, p, "pid", mrb_f_pid, ARGS_NONE());
  mrb_define_class_method(mrb, p, "ppid", mrb_f_ppid, ARGS_NONE());

  mrb_gv_set(mrb, mrb_intern(mrb, "$$"), mrb_fixnum_value((mrb_int)getpid()));
}