Ejemplo n.º 1
0
void
mrb_mruby_kernel_ext_gem_init(mrb_state *mrb)
{
  struct RClass *krn = mrb->kernel_module;

  mrb_define_module_function(mrb, krn, "fail", mrb_f_raise, MRB_ARGS_OPT(2));
  mrb_define_method(mrb, krn, "__method__", mrb_f_method, MRB_ARGS_NONE());
  mrb_define_module_function(mrb, krn, "String", mrb_f_string, MRB_ARGS_REQ(1));
  mrb_define_module_function(mrb, krn, "Array", mrb_f_array, MRB_ARGS_REQ(1));
}
Ejemplo n.º 2
0
void
mrb_mruby_fiber_gem_init(mrb_state* mrb)
{
  struct RClass *c;

  c = mrb_define_class(mrb, "Fiber", mrb->object_class);
  MRB_SET_INSTANCE_TT(c, MRB_TT_FIBER);

  mrb_define_method(mrb, c, "initialize", fiber_init,    MRB_ARGS_NONE());
  mrb_define_method(mrb, c, "resume",     fiber_resume,  MRB_ARGS_ANY());
  mrb_define_method(mrb, c, "transfer",   fiber_transfer, MRB_ARGS_ANY());
  mrb_define_method(mrb, c, "alive?",     fiber_alive_p, MRB_ARGS_NONE());
  mrb_define_method(mrb, c, "==",         fiber_eq,      MRB_ARGS_REQ(1));

  mrb_define_class_method(mrb, c, "yield", fiber_yield, MRB_ARGS_ANY());
  mrb_define_class_method(mrb, c, "current", fiber_current, MRB_ARGS_NONE());

  mrb_define_class(mrb, "FiberError", mrb->eStandardError_class);
}
Ejemplo n.º 3
0
void mrb_UV_Sockaddr_init(mrb_state* mrb) {
  static int initialized = 0;
  if (initialized) return;
  else initialized = 1;

  struct RClass* Sockaddr_class = mrb_define_class_under(mrb, UV_module(mrb), "Sockaddr", mrb->object_class);
  MRB_SET_INSTANCE_TT(Sockaddr_class, MRB_TT_DATA);

  mrb_define_method(mrb, Sockaddr_class, "initialize", mrb_UV_Sockaddr_initialize, MRB_ARGS_NONE());
}
Ejemplo n.º 4
0
void
mrb_mruby_numeric_ext_gem_init(mrb_state* mrb)
{
  struct RClass *i = mrb_module_get(mrb, "Integral");

  mrb_define_method(mrb, i, "chr", mrb_int_chr, MRB_ARGS_NONE());
  mrb_define_method(mrb, i, "allbits?", mrb_int_allbits, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, i, "anybits?", mrb_int_anybits, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, i, "nobits?", mrb_int_nobits, MRB_ARGS_REQ(1));
}
Ejemplo n.º 5
0
void mrb_UV_TCP_init(mrb_state* mrb) {
  static int initialized = 0;
  if (initialized) return;
  else initialized = 1;
  
  struct RClass* TCP_class = mrb_define_class_under(mrb, UV_module(mrb), "TCP", Stream_class(mrb));
  MRB_SET_INSTANCE_TT(TCP_class, MRB_TT_DATA);

  mrb_define_method(mrb, TCP_class, "initialize", mrb_UV_TCP_initialize, MRB_ARGS_NONE());
}
Ejemplo n.º 6
0
void
mrb_mruby_rtos_toppers_gem_init(mrb_state *mrb)
{
  struct RClass *rtos;
  struct RClass *tsk;
  mrb_value wmd;
  mrb_value tmo;

  /* RTOS module */
  rtos = mrb_define_module(mrb, "RTOS");

  /* RTOS api */
  mrb_define_module_function(mrb, rtos, "delay",  mrb_rtos_delay,   MRB_ARGS_REQ(1));
  mrb_define_module_function(mrb, rtos, "millis", mrb_rtos_millis,  MRB_ARGS_NONE());

  wmd = mrb_hash_new(mrb);
  mrb_hash_set(mrb, wmd, mrb_symbol_value(mrb_intern_lit(mrb, "and")),   mrb_fixnum_value(TWF_ANDW));
  mrb_hash_set(mrb, wmd, mrb_symbol_value(mrb_intern_lit(mrb, "or")),    mrb_fixnum_value(TWF_ORW));
  mrb_mod_cv_set(mrb, rtos, mrb_intern_lit(mrb, "WAITMODE"), wmd);

  tmo = mrb_hash_new(mrb);
  mrb_hash_set(mrb, tmo, mrb_symbol_value(mrb_intern_lit(mrb, "polling")), mrb_fixnum_value(TMO_POL));
  mrb_hash_set(mrb, tmo, mrb_symbol_value(mrb_intern_lit(mrb, "forever")), mrb_fixnum_value(TMO_FEVR));
  mrb_mod_cv_set(mrb, rtos, mrb_intern_lit(mrb, "TIMEOUT"), tmo);

  /* Task class */
  tsk = mrb_define_class_under(mrb, rtos, "Task", mrb->object_class);

  mrb_define_method(mrb, tsk, "initialize", mrb_task_init,      MRB_ARGS_REQ(1));
  mrb_define_method(mrb, tsk, "activate",   mrb_task_activate,  MRB_ARGS_NONE());
  mrb_define_method(mrb, tsk, "suspend",    mrb_task_suspend,   MRB_ARGS_NONE());
  mrb_define_method(mrb, tsk, "resume",     mrb_task_resume,    MRB_ARGS_NONE());
  mrb_define_method(mrb, tsk, "terminate",  mrb_task_terminate, MRB_ARGS_NONE());

  /* EventFlag class */
  mrb_rtos_flag_init(mrb, rtos);

  /* MemoryPool, MemoryBuffer */
  mrb_rtos_memory_init(mrb, rtos);

  /* DataQueue */
  mrb_rtos_dataqueue_init(mrb, rtos);
}
Ejemplo n.º 7
0
void inputBindingInit(mrb_state *mrb)
{
	RClass *module = mrb_define_module(mrb, "Input");

	mrb_define_module_function(mrb, module, "update", inputUpdate, MRB_ARGS_NONE());
	mrb_define_module_function(mrb, module, "press?", inputPress, MRB_ARGS_REQ(1));
	mrb_define_module_function(mrb, module, "trigger?", inputTrigger, MRB_ARGS_REQ(1));
	mrb_define_module_function(mrb, module, "repeat?", inputRepeat, MRB_ARGS_REQ(1));
	mrb_define_module_function(mrb, module, "dir4", inputDir4, MRB_ARGS_NONE());
	mrb_define_module_function(mrb, module, "dir8", inputDir8, MRB_ARGS_NONE());

	DEF_CONST_I("DOWN",  Input::Down );
	DEF_CONST_I("LEFT",  Input::Left );
	DEF_CONST_I("RIGHT", Input::Right);
	DEF_CONST_I("UP",    Input::Up   );

	DEF_CONST_I("A",     Input::A    );
	DEF_CONST_I("B",     Input::B    );
	DEF_CONST_I("C",     Input::C    );
	DEF_CONST_I("X",     Input::X    );
	DEF_CONST_I("Y",     Input::Y    );
	DEF_CONST_I("Z",     Input::Z    );
	DEF_CONST_I("L",     Input::L    );
	DEF_CONST_I("R",     Input::R    );

	DEF_CONST_I("SHIFT", Input::Shift);
	DEF_CONST_I("CTRL",  Input::Ctrl );
	DEF_CONST_I("ALT",   Input::Alt  );

	DEF_CONST_I("F5",    Input::F5   );
	DEF_CONST_I("F6",    Input::F6   );
	DEF_CONST_I("F7",    Input::F7   );
	DEF_CONST_I("F8",    Input::F8   );
	DEF_CONST_I("F9",    Input::F9   );

	mrb_define_module_function(mrb, module, "mouse_x", inputMouseX, MRB_ARGS_NONE());
	mrb_define_module_function(mrb, module, "mouse_y", inputMouseY, MRB_ARGS_NONE());

	DEF_CONST_I("MOUSELEFT",   Input::MouseLeft  );
	DEF_CONST_I("MOUSEMIDDLE", Input::MouseMiddle);
	DEF_CONST_I("MOUSERIGHT",  Input::MouseRight );
}
Ejemplo n.º 8
0
void mrb_mruby_mongo_gem_init(mrb_state* mrb) {
  struct RClass *class_mongo = mrb_define_module(mrb, "Mongo");

  struct RClass *class_mongo_bson = mrb_define_class_under(mrb, class_mongo, "Bson", mrb->object_class);
  mrb_define_method(mrb, class_mongo_bson, "initialize", mrb_mongo_bson_init, MRB_ARGS_OPT(1));
  mrb_define_method(mrb, class_mongo_bson, "to_json", mrb_mongo_to_json, MRB_ARGS_NONE());

  struct RClass *class_mongo_client = mrb_define_class_under(mrb, class_mongo, "Client", mrb->object_class);
  mrb_define_method(mrb, class_mongo_client, "initialize", mrb_mongo_client_init, MRB_ARGS_OPT(1));
  mrb_define_method(mrb, class_mongo_client, "databases", mrb_mongo_client_databases, MRB_ARGS_NONE());
  mrb_define_method(mrb, class_mongo_client, "[]", mrb_mongo_client_find_database, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, class_mongo_client, "address", mrb_mongo_client_get_address, MRB_ARGS_NONE());
  mrb_define_method(mrb, class_mongo_client, "database_exists?", mrb_mongo_client_database_exists, MRB_ARGS_REQ(1));

  struct RClass *class_mongo_database = mrb_define_class_under(mrb, class_mongo, "Database", mrb->object_class);
  mrb_define_method(mrb, class_mongo_database, "initialize", mrb_mongo_database_init, MRB_ARGS_REQ(2));
  mrb_define_method(mrb, class_mongo_database, "client", mrb_mongo_database_get_client, MRB_ARGS_NONE());
  mrb_define_method(mrb, class_mongo_database, "collections", mrb_mongo_database_collections, MRB_ARGS_NONE());
  mrb_define_method(mrb, class_mongo_database, "[]", mrb_mongo_database_find_collection, MRB_ARGS_REQ(1));

  struct RClass *class_mongo_collection = mrb_define_class_under(mrb, class_mongo, "Collection", mrb->object_class);
  mrb_define_method(mrb, class_mongo_collection, "initialize", mrb_mongo_collection_init, MRB_ARGS_REQ(2));
  mrb_define_method(mrb, class_mongo_collection, "database", mrb_mongo_collection_get_database, MRB_ARGS_NONE());
  mrb_define_method(mrb, class_mongo_collection, "count", mrb_mongo_collection_count, MRB_ARGS_NONE());
  mrb_define_method(mrb, class_mongo_collection, "insert", mrb_mongo_collection_insert, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, class_mongo_collection, "drop", mrb_mongo_collection_drop, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, class_mongo_collection, "update", mrb_mongo_collection_update, MRB_ARGS_REQ(2));
  mrb_define_method(mrb, class_mongo_collection, "where", mrb_mongo_collection_query, MRB_ARGS_OPT(1));

  struct RClass *class_mongo_query  = mrb_define_class_under(mrb, class_mongo, "Query", mrb->object_class);
  mrb_define_method(mrb, class_mongo_query, "initialize", mrb_mongo_query_init, MRB_ARGS_REQ(2));
  mrb_define_method(mrb, class_mongo_query, "sort", mrb_mongo_query_sort, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, class_mongo_query, "limit", mrb_mongo_query_limit, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, class_mongo_query, "skip", mrb_mongo_query_skip, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, class_mongo_query, "fields", mrb_mongo_query_fields, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, class_mongo_query, "count", mrb_mongo_query_count, MRB_ARGS_NONE());
  mrb_define_method(mrb, class_mongo_query, "to_a", mrb_mongo_query_to_array, MRB_ARGS_NONE());

  mongoc_init();

  DONE;
}
Ejemplo n.º 9
0
Archivo: proc.c Proyecto: herumi/mruby
void
mrb_init_proc(mrb_state *mrb)
{
  struct RProc *m;
  mrb_irep *call_irep = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep));
  static const mrb_irep mrb_irep_zero = { 0 };
  mrbjit_code_info *cinfo;
  int i;

  if (call_irep == NULL)
    return;

  *call_irep = mrb_irep_zero;
  call_irep->flags = MRB_ISEQ_NO_FREE;
  call_irep->iseq = call_iseq;
  call_irep->ilen = 2;
  call_irep->jit_entry_tab = (mrbjit_codetab *)mrb_calloc(mrb, 2, sizeof(mrbjit_codetab));
  for (i = 0; i < 2; i++) {
    call_irep->jit_entry_tab[i].size = 16;
    cinfo = (mrbjit_code_info *)mrb_calloc(mrb, 16, sizeof(mrbjit_code_info));
    call_irep->jit_entry_tab[i].body = cinfo;
  }
  call_irep->prof_info = (int *)mrb_calloc(mrb, 2, sizeof(int));
  call_irep->method_kind = NORMAL;
  call_irep->jit_top_entry = NULL;
  call_irep->simple_lambda = 1;
  call_irep->proc_obj = NULL;

  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, MRB_ARGS_NONE());
  mrb_define_method(mrb, mrb->proc_class, "initialize_copy", mrb_proc_init_copy, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, mrb->proc_class, "arity", mrb_proc_arity, MRB_ARGS_NONE());

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

  mrb_define_class_method(mrb, mrb->kernel_module, "lambda", proc_lambda, MRB_ARGS_NONE()); /* 15.3.1.2.6  */
  mrb_define_method(mrb, mrb->kernel_module,       "lambda", proc_lambda, MRB_ARGS_NONE()); /* 15.3.1.3.27 */
}
Ejemplo n.º 10
0
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, MRB_ARGS_ANY());
  mrb_define_method(mrb, e, "exception", exc_exception, MRB_ARGS_ANY());
  mrb_define_method(mrb, e, "initialize", exc_initialize, MRB_ARGS_ANY());
  mrb_define_method(mrb, e, "==", exc_equal, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, e, "to_s", exc_to_s, MRB_ARGS_NONE());
  mrb_define_method(mrb, e, "message", exc_message, MRB_ARGS_NONE());
  mrb_define_method(mrb, e, "inspect", exc_inspect, MRB_ARGS_NONE());
  mrb_define_method(mrb, e, "backtrace", mrb_get_backtrace, MRB_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 */
  e = mrb_define_class(mrb, "ScriptError",  mrb->eException_class);                                    /* 15.2.37 */
  mrb_define_class(mrb, "SyntaxError",  e);                                                            /* 15.2.38 */
}
Ejemplo n.º 11
0
void
mrb_mruby_rs_serial_gem_init(mrb_state* mrb) {
	struct RClass *serial;
	serial = mrb_define_class(mrb, "Serial", mrb->object_class);

	/* methods */
	mrb_define_method(mrb, serial, "initialize", mrb_rs_serial_initialize, MRB_ARGS_NONE());
	mrb_define_method(mrb, serial, "write", mrb_rs_serial_write, MRB_ARGS_REQ(1));
	mrb_define_method(mrb, serial, "puts", mrb_rs_serial_puts, MRB_ARGS_REQ(1));

}
Ejemplo n.º 12
0
void
mruby_allegro_config_init(mrb_state *mrb)
{
  struct RClass *am = M_ALLEGRO;
  struct RClass *cc = mrb_define_class_under(mrb, am, "Config", mrb->object_class);
  MRB_SET_INSTANCE_TT(cc, MRB_TT_DATA);
  mrb_define_class_method(mrb, cc, "create", config_create, MRB_ARGS_NONE());
  mrb_define_alias(mrb, cc->c, "new", "create");
  mrb_define_method(mrb, cc, "destroy", config_destroy, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "destroyed?", config_destroyed, MRB_ARGS_NONE());
  mrb_define_class_method(mrb, cc, "load_file", config_load_file, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, cc, "save_file", config_save_file, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, cc, "add_section", config_add_section, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, cc, "add_comment", config_add_comment, MRB_ARGS_REQ(2));
  mrb_define_method(mrb, cc, "get_value", config_get_value, MRB_ARGS_REQ(2));
  mrb_define_method(mrb, cc, "set_value", config_set_value, MRB_ARGS_REQ(3));
  mrb_define_method(mrb, cc, "merge", config_merge, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, cc, "merge_into", config_merge_into, MRB_ARGS_REQ(1));
  mrb_define_alias(mrb, cc, "merge!", "merge_into");
}
Ejemplo n.º 13
0
void
mrb_mruby_error_gem_test(mrb_state *mrb)
{
  struct RClass *cls;

  cls = mrb_define_class(mrb, "ExceptionTest", mrb->object_class);
  mrb_define_module_function(mrb, cls, "mrb_protect", run_protect, MRB_ARGS_NONE() | MRB_ARGS_BLOCK());
  mrb_define_module_function(mrb, cls, "mrb_ensure", run_ensure, MRB_ARGS_REQ(2));
  mrb_define_module_function(mrb, cls, "mrb_rescue", run_rescue, MRB_ARGS_REQ(2));
  mrb_define_module_function(mrb, cls, "mrb_rescue_exceptions", run_rescue_exceptions, MRB_ARGS_REQ(2));
}
Ejemplo n.º 14
0
Archivo: dl.c Proyecto: mattn/mruby-uv
void
mrb_mruby_uv_gem_init_dl(mrb_state *mrb, struct RClass *UV)
{
  struct RClass *class_uv_dl;

  class_uv_dl = mrb_define_class_under(mrb, UV, "DL", mrb->object_class);
  MRB_SET_INSTANCE_TT(class_uv_dl, MRB_TT_DATA);
  mrb_define_method(mrb, class_uv_dl, "initialize", mrb_f_uv_dlopen, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, class_uv_dl, "close", mrb_f_uv_dlclose, MRB_ARGS_NONE());
  mrb_define_method(mrb, class_uv_dl, "sym", mrb_f_uv_dlsym, MRB_ARGS_REQ(1));
}
Ejemplo n.º 15
0
static void
grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx)
{
  mrb_state *mrb = ctx->impl->mrb.state;

  mrb->ud = ctx;
  ctx->impl->mrb.module = mrb_define_module(mrb, "Groonga");
  mrb_define_class_method(mrb, ctx->impl->mrb.module,
                          "init", mrb_groonga_init, MRB_ARGS_NONE());
  mrb_funcall(mrb, mrb_obj_value(ctx->impl->mrb.module), "init", 0);
}
Ejemplo n.º 16
0
void mrb_init_exception(mrb_state *mrb)
{
    RClass *e;

    e = mrb->eException_class = &mrb->define_class("Exception", mrb->object_class);        /* 15.2.22 */
    e->define_class_method("exception", mrb_instance_new, MRB_ARGS_ANY())
            .define_method("exception", exc_exception, MRB_ARGS_ANY())
            .define_method("initialize", exc_initialize, MRB_ARGS_ANY())
            .define_method("==", exc_equal, MRB_ARGS_REQ(1))
            .define_method("to_s", exc_to_s, MRB_ARGS_NONE())
            .define_method("message", exc_message, MRB_ARGS_NONE())
            .define_method("inspect", exc_inspect, MRB_ARGS_NONE())
            .define_method("backtrace", mrb_exc_backtrace, MRB_ARGS_NONE())
            .fin();

    mrb->eStandardError_class = &mrb->define_class("StandardError",       mrb->eException_class);       /* 15.2.23 */
    mrb->define_class("RuntimeError", mrb->eStandardError_class);                                       /* 15.2.28 */
    e = &mrb->define_class("ScriptError",  mrb->eException_class);                                    /* 15.2.37 */
    mrb->define_class("SyntaxError",  e);                                                           /* 15.2.38 */
}
void
mrb_magnetic_init(mrb_state* mrb)
{
  struct RClass *platform;
  struct RClass *magnetic;

  platform = mrb_class_get(mrb, "Platform");
  magnetic = mrb_define_class_under(mrb, platform, "Magnetic", mrb->object_class);

  mrb_define_class_method(mrb , magnetic , "_read" , mrb_magnetic_s__read , MRB_ARGS_NONE());
}
Ejemplo n.º 18
0
void
mrb_mruby_errno_gem_init(mrb_state *mrb)
{
  struct RClass *e, *eno, *sce, *ste;
  mrb_value h, noerror;

  ste = mrb_class_get(mrb, "StandardError");

  sce = mrb_define_class(mrb, "SystemCallError", ste);
  mrb_define_class_method(mrb, sce, "_sys_fail", mrb_sce_sys_fail, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, sce, "errno", mrb_sce_errno, MRB_ARGS_NONE());
  mrb_define_method(mrb, sce, "to_s", mrb_sce_to_s, MRB_ARGS_NONE());
  mrb_define_method(mrb, sce, "initialize", mrb_sce_init, MRB_ARGS_ARG(1, 1));

  eno = mrb_define_module(mrb, "Errno");
  h = mrb_hash_new(mrb);
  mrb_define_const(mrb, eno, "Errno2class", h);

  e = mrb_define_class_under(mrb, eno, "NOERROR", sce);
  mrb_define_const(mrb, e, "Errno", mrb_fixnum_value(0));
  mrb_define_method(mrb, e, "initialize", mrb_exxx_init, MRB_ARGS_OPT(1));
  //mrb_define_method(mrb, e, "===", mrb_exxx_cmp, MRB_ARGS_REQ(1));
  noerror = mrb_obj_value(e);

#define itsdefined(SYM) \
  do {									\
    int ai = mrb_gc_arena_save(mrb);					\
    e = mrb_define_class_under(mrb, eno, #SYM, sce);			\
    mrb_define_const(mrb, e, "Errno", mrb_fixnum_value(SYM));		\
    mrb_define_method(mrb, e, "initialize", mrb_exxx_init, MRB_ARGS_OPT(1)); \
    mrb_hash_set(mrb, h, mrb_fixnum_value(SYM), mrb_obj_value(e));	\
    mrb_gc_arena_restore(mrb, ai);					\
  } while (0)

#define itsnotdefined(SYM) \
  do {									\
    mrb_define_const(mrb, eno, #SYM, noerror);				\
  } while (0)

#include "known_errors_def.cstub"
}
Ejemplo n.º 19
0
void mrb_SDL_NSWindow_init(mrb_state* mrb) {
  RClass* NSWindow_class = mrb_define_class_under(mrb, SDL_module(mrb), "NSWindow", mrb->object_class);
  MRB_SET_INSTANCE_TT(NSWindow_class, MRB_TT_DATA);

#if BIND_NSWindow_INITIALIZE
  mrb_define_method(mrb, NSWindow_class, "initialize", mrb_SDL_NSWindow_initialize, MRB_ARGS_NONE());
#endif
  mrb_define_class_method(mrb, NSWindow_class, "disown", mrb_SDL_NSWindow_disown, MRB_ARGS_ARG(1, 0));
  mrb_define_class_method(mrb, NSWindow_class, "belongs_to_ruby?", mrb_SDL_NSWindow_belongs_to_ruby, MRB_ARGS_ARG(1, 0));


}
Ejemplo n.º 20
0
void
grn_mrb_bulk_init(grn_ctx *ctx)
{
  grn_mrb_data *data = &(ctx->impl->mrb);
  mrb_state *mrb = data->state;
  struct RClass *module = data->module;
  struct RClass *klass;

  klass = mrb_define_class_under(mrb, module, "Bulk", mrb->object_class);
  MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
  mrb_define_method(mrb, klass, "initialize",
                    mrb_grn_bulk_initialize, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, klass, "domain",
                    mrb_grn_bulk_get_domain, MRB_ARGS_NONE());
  mrb_define_method(mrb, klass, "value",
                    mrb_grn_bulk_get_value, MRB_ARGS_NONE());
  mrb_define_method(mrb, klass, "==",
                    mrb_grn_bulk_equal, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, klass, "inspect",
                    grn_mrb_object_inspect, MRB_ARGS_NONE());
}
Ejemplo n.º 21
0
void
grn_mrb_procedure_init(grn_ctx *ctx)
{
  grn_mrb_data *data = &(ctx->impl->mrb);
  mrb_state *mrb = data->state;
  struct RClass *module = data->module;
  struct RClass *object_class = data->object_class;
  struct RClass *klass;

  klass = mrb_define_class_under(mrb, module, "Procedure", object_class);
  MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
  mrb_define_method(mrb, klass, "initialize",
                    mrb_grn_procedure_initialize, MRB_ARGS_REQ(1));

  mrb_define_method(mrb, klass, "selector?",
                    mrb_grn_procedure_selector_p, MRB_ARGS_NONE());
  mrb_define_method(mrb, klass, "selector_only?",
                    mrb_grn_procedure_selector_only_p, MRB_ARGS_NONE());
  mrb_define_method(mrb, klass, "scorer?",
                    mrb_grn_procedure_scorer_p, MRB_ARGS_NONE());
}
Ejemplo n.º 22
0
void mrb_directfb_define_input_device(mrb_state* mrb, struct RClass* outer)
{
    // def DirectFB::InputDevice
    struct RClass* input_device = mrb_define_class_under(mrb, outer, "InputDevice", mrb->object_class);
    MRB_SET_INSTANCE_TT(input_device, MRB_TT_DATA);

    mrb_define_method(mrb, input_device, "release", input_device_release, MRB_ARGS_NONE());
    mrb_define_method(mrb, input_device, "get_id", input_device_get_id, MRB_ARGS_NONE());
    mrb_define_method(mrb, input_device, "get_description", input_device_get_description, MRB_ARGS_NONE());
    mrb_define_method(mrb, input_device, "get_keymap_entry", input_device_get_keymap_entry, MRB_ARGS_REQ(1));
    mrb_define_method(mrb, input_device, "create_event_buffer", input_device_create_event_buffer, MRB_ARGS_NONE());
    mrb_define_method(mrb, input_device, "attach_event_buffer", input_device_attach_event_buffer, MRB_ARGS_REQ(1));
    mrb_define_method(mrb, input_device, "detach_event_buffer", input_device_detach_event_buffer, MRB_ARGS_REQ(1));
    mrb_define_method(mrb, input_device, "get_key_state", input_device_get_key_state, MRB_ARGS_REQ(1));
    mrb_define_method(mrb, input_device, "get_modifiers", input_device_get_modifiers, MRB_ARGS_NONE());
    mrb_define_method(mrb, input_device, "get_lock_state", input_device_get_lock_state, MRB_ARGS_NONE());
    mrb_define_method(mrb, input_device, "get_buttons", input_device_get_buttons, MRB_ARGS_NONE());
    mrb_define_method(mrb, input_device, "get_button_state", input_device_get_button_state, MRB_ARGS_REQ(1));
    mrb_define_method(mrb, input_device, "get_axis", input_device_get_axis, MRB_ARGS_REQ(1));
    mrb_define_method(mrb, input_device, "get_xy", input_device_get_xy, MRB_ARGS_NONE());
}
Ejemplo n.º 23
0
void
grn_mrb_obj_init(grn_ctx *ctx)
{
  grn_mrb_data *data = &(ctx->impl->mrb);
  mrb_state *mrb = data->state;
  struct RClass *module = data->module;
  struct RClass *klass;

  klass = mrb_define_class_under(mrb, module, "Object", mrb->object_class);
  MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
  data->object_class = klass;

  mrb_define_method(mrb, klass, "name", object_get_name, MRB_ARGS_NONE());
  mrb_define_method(mrb, klass, "find_index",
                    object_find_index, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, klass, "grn_inspect",
                    object_grn_inspect, MRB_ARGS_NONE());
  mrb_define_method(mrb, klass, "==", object_equal, MRB_ARGS_REQ(1));

  grn_mrb_load(ctx, "index_info.rb");
}
Ejemplo n.º 24
0
void
grn_mrb_thread_init(grn_ctx *ctx)
{
  mrb_state *mrb = ctx->impl->mrb.state;
  struct RClass *module = ctx->impl->mrb.module;
  struct RClass *thread_module;

  thread_module = mrb_define_module_under(mrb, module, "Thread");

  mrb_define_class_method(mrb, thread_module,
                          "limit", thread_limit, MRB_ARGS_NONE());
}
Ejemplo n.º 25
0
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_module_get(mrb, "Enumerable")); /* 15.2.20.3 */
#ifndef _WIN32
  mrb_define_class_method(mrb, io, "_popen",  mrb_io_s_popen,   MRB_ARGS_ANY());
  mrb_define_class_method(mrb, io, "_sysclose",  mrb_io_s_sysclose, MRB_ARGS_REQ(1));
#endif
  mrb_define_class_method(mrb, io, "select",  mrb_io_s_select,  MRB_ARGS_ANY());
  mrb_define_class_method(mrb, io, "sysopen", mrb_io_s_sysopen, MRB_ARGS_ANY());

  mrb_define_method(mrb, io, "initialize", mrb_io_initialize, MRB_ARGS_ANY());    /* 15.2.20.5.21 (x)*/
  mrb_define_method(mrb, io, "sync",       mrb_io_sync,       MRB_ARGS_NONE());
  mrb_define_method(mrb, io, "sync=",      mrb_io_set_sync,   MRB_ARGS_REQ(1));
  mrb_define_method(mrb, io, "sysread",    mrb_io_sysread,    MRB_ARGS_ANY());
  mrb_define_method(mrb, io, "sysseek",    mrb_io_sysseek,    MRB_ARGS_REQ(1));
  mrb_define_method(mrb, io, "syswrite",   mrb_io_syswrite,   MRB_ARGS_REQ(1));
  mrb_define_method(mrb, io, "close",      mrb_io_close,      MRB_ARGS_NONE());   /* 15.2.20.5.1 */
  mrb_define_method(mrb, io, "close_on_exec=", mrb_io_set_close_on_exec, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, io, "close_on_exec?", mrb_io_close_on_exec_p,   MRB_ARGS_NONE());
  mrb_define_method(mrb, io, "closed?",    mrb_io_closed,     MRB_ARGS_NONE());   /* 15.2.20.5.2 */
  mrb_define_method(mrb, io, "pid",        mrb_io_pid,        MRB_ARGS_NONE());   /* 15.2.20.5.2 */
  mrb_define_method(mrb, io, "fileno",     mrb_io_fileno,     MRB_ARGS_NONE());


  mrb_gv_set(mrb, mrb_intern_cstr(mrb, "$/"), mrb_str_new_cstr(mrb, "\n"));
}
Ejemplo n.º 26
0
void
mrb_init_file(mrb_state *mrb)
{
  struct RClass *io, *file, *cnst;

  io   = mrb_class_get(mrb, "IO");
  file = mrb_define_class(mrb, "File", io);
  MRB_SET_INSTANCE_TT(file, MRB_TT_DATA);
  mrb_define_class_method(mrb, file, "umask",  mrb_file_s_umask, MRB_ARGS_REQ(1));
  mrb_define_class_method(mrb, file, "delete", mrb_file_s_unlink, MRB_ARGS_ANY());
  mrb_define_class_method(mrb, file, "unlink", mrb_file_s_unlink, MRB_ARGS_ANY());
  mrb_define_class_method(mrb, file, "rename", mrb_file_s_rename, MRB_ARGS_REQ(2));
  mrb_define_class_method(mrb, file, "symlink", mrb_file_s_symlink, MRB_ARGS_REQ(2));
  mrb_define_class_method(mrb, file, "chmod", mrb_file_s_chmod, MRB_ARGS_REQ(1) | MRB_ARGS_REST());
  mrb_define_class_method(mrb, file, "readlink", mrb_file_s_readlink, MRB_ARGS_REQ(1));

  mrb_define_class_method(mrb, file, "dirname",   mrb_file_dirname,    MRB_ARGS_REQ(1));
  mrb_define_class_method(mrb, file, "basename",  mrb_file_basename,   MRB_ARGS_REQ(1));
  mrb_define_class_method(mrb, file, "realpath",  mrb_file_realpath,   MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
  mrb_define_class_method(mrb, file, "_getwd",    mrb_file__getwd,     MRB_ARGS_NONE());
  mrb_define_class_method(mrb, file, "_gethome",  mrb_file__gethome,   MRB_ARGS_OPT(1));

  mrb_define_method(mrb, file, "flock", mrb_file_flock, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, file, "mtime", mrb_file_mtime, MRB_ARGS_NONE());

  cnst = mrb_define_module_under(mrb, file, "Constants");
  mrb_define_const(mrb, cnst, "LOCK_SH", mrb_fixnum_value(LOCK_SH));
  mrb_define_const(mrb, cnst, "LOCK_EX", mrb_fixnum_value(LOCK_EX));
  mrb_define_const(mrb, cnst, "LOCK_UN", mrb_fixnum_value(LOCK_UN));
  mrb_define_const(mrb, cnst, "LOCK_NB", mrb_fixnum_value(LOCK_NB));
  mrb_define_const(mrb, cnst, "SEPARATOR", mrb_str_new_cstr(mrb, FILE_SEPARATOR));
  mrb_define_const(mrb, cnst, "PATH_SEPARATOR", mrb_str_new_cstr(mrb, PATH_SEPARATOR));
#if defined(_WIN32) || defined(_WIN64)
  mrb_define_const(mrb, cnst, "ALT_SEPARATOR", mrb_str_new_cstr(mrb, FILE_ALT_SEPARATOR));
#else
  mrb_define_const(mrb, cnst, "ALT_SEPARATOR", mrb_nil_value());
#endif
  mrb_define_const(mrb, cnst, "NULL", mrb_str_new_cstr(mrb, NULL_FILE));

}
Ejemplo n.º 27
0
void
mrb_init_hash(mrb_state *mrb)
{
  struct RClass *h;

  h = mrb->hash_class = mrb_define_class(mrb, "Hash", mrb->object_class);
  MRB_SET_INSTANCE_TT(h, MRB_TT_HASH);

  mrb_include_module(mrb, h, mrb_class_get(mrb, "Enumerable"));
  mrb_define_method(mrb, h, "==",              mrb_hash_equal,       MRB_ARGS_REQ(1)); /* 15.2.13.4.1  */
  mrb_define_method(mrb, h, "[]",              mrb_hash_aget,        MRB_ARGS_REQ(1)); /* 15.2.13.4.2  */
  mrb_define_method(mrb, h, "[]=",             mrb_hash_aset,        MRB_ARGS_REQ(2)); /* 15.2.13.4.3  */
  mrb_define_method(mrb, h, "clear",           mrb_hash_clear,       MRB_ARGS_NONE()); /* 15.2.13.4.4  */
  mrb_define_method(mrb, h, "default",         mrb_hash_default,     MRB_ARGS_ANY());  /* 15.2.13.4.5  */
  mrb_define_method(mrb, h, "default=",        mrb_hash_set_default, MRB_ARGS_REQ(1)); /* 15.2.13.4.6  */
  mrb_define_method(mrb, h, "default_proc",    mrb_hash_default_proc,MRB_ARGS_NONE()); /* 15.2.13.4.7  */
  mrb_define_method(mrb, h, "default_proc=",   mrb_hash_set_default_proc,MRB_ARGS_REQ(1)); /* 15.2.13.4.7  */
  mrb_define_method(mrb, h, "__delete",        mrb_hash_delete,      MRB_ARGS_REQ(1)); /* core of 15.2.13.4.8  */
  mrb_define_method(mrb, h, "empty?",          mrb_hash_empty_p,     MRB_ARGS_NONE()); /* 15.2.13.4.12 */
  mrb_define_method(mrb, h, "has_key?",        mrb_hash_has_key,     MRB_ARGS_REQ(1)); /* 15.2.13.4.13 */
  mrb_define_method(mrb, h, "has_value?",      mrb_hash_has_value,   MRB_ARGS_REQ(1)); /* 15.2.13.4.14 */
  mrb_define_method(mrb, h, "include?",        mrb_hash_has_key,     MRB_ARGS_REQ(1)); /* 15.2.13.4.15 */
  mrb_define_method(mrb, h, "__init_core",     mrb_hash_init_core,   MRB_ARGS_ANY());  /* core of 15.2.13.4.16 */
  mrb_define_method(mrb, h, "initialize_copy", mrb_hash_replace,     MRB_ARGS_REQ(1)); /* 15.2.13.4.17 */
  mrb_define_method(mrb, h, "key?",            mrb_hash_has_key,     MRB_ARGS_REQ(1)); /* 15.2.13.4.18 */
  mrb_define_method(mrb, h, "keys",            mrb_hash_keys,        MRB_ARGS_NONE()); /* 15.2.13.4.19 */
  mrb_define_method(mrb, h, "length",          mrb_hash_size_m,      MRB_ARGS_NONE()); /* 15.2.13.4.20 */
  mrb_define_method(mrb, h, "member?",         mrb_hash_has_key,     MRB_ARGS_REQ(1)); /* 15.2.13.4.21 */
  mrb_define_method(mrb, h, "replace",         mrb_hash_replace,     MRB_ARGS_REQ(1)); /* 15.2.13.4.23 */
  mrb_define_method(mrb, h, "shift",           mrb_hash_shift,       MRB_ARGS_NONE()); /* 15.2.13.4.24 */
  mrb_define_method(mrb, h, "size",            mrb_hash_size_m,      MRB_ARGS_NONE()); /* 15.2.13.4.25 */
  mrb_define_method(mrb, h, "store",           mrb_hash_aset,        MRB_ARGS_REQ(2)); /* 15.2.13.4.26 */
  mrb_define_method(mrb, h, "value?",          mrb_hash_has_value,   MRB_ARGS_REQ(1)); /* 15.2.13.4.27 */
  mrb_define_method(mrb, h, "values",          mrb_hash_values,      MRB_ARGS_NONE()); /* 15.2.13.4.28 */

  mrb_define_method(mrb, h, "to_hash",         mrb_hash_to_hash,     MRB_ARGS_NONE()); /* 15.2.13.4.29 (x)*/
  mrb_define_method(mrb, h, "inspect",         mrb_hash_inspect,     MRB_ARGS_NONE()); /* 15.2.13.4.30 (x)*/
  mrb_define_alias(mrb,  h, "to_s",            "inspect");                             /* 15.2.13.4.31 (x)*/
  mrb_define_method(mrb, h, "eql?",            mrb_hash_eql,         MRB_ARGS_REQ(1)); /* 15.2.13.4.32 (x)*/
}
Ejemplo n.º 28
0
void mrb_ipvs_service_class_init(mrb_state *mrb, struct RClass *_class_ipvs) {
  struct RClass *_class_ipvs_service;

  _class_ipvs_service =
      mrb_define_class_under(mrb, _class_ipvs, "Service", mrb->object_class);
  MRB_SET_INSTANCE_TT(_class_ipvs_service, MRB_TT_DATA);
  mrb_define_method(mrb, _class_ipvs_service, "initialize",
                    mrb_ipvs_service_init, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, _class_ipvs_service, "initialize_copy",
                    mrb_ipvs_service_init_copy,
                    MRB_ARGS_REQ(1) | MRB_ARGS_OPT(6));
  mrb_define_method(mrb, _class_ipvs_service, "add_service",
                    mrb_ipvs_service_add, MRB_ARGS_NONE());
  mrb_define_method(mrb, _class_ipvs_service, "del_service",
                    mrb_ipvs_service_del, MRB_ARGS_NONE());
  mrb_define_method(mrb, _class_ipvs_service, "add_dest",
                    mrb_ipvs_service_add_dest, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, _class_ipvs_service, "del_dest",
                    mrb_ipvs_service_del_dest, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, _class_ipvs_service, "addr", mrb_ipvs_service_get_addr,
                    MRB_ARGS_NONE());
  mrb_define_method(mrb, _class_ipvs_service, "port", mrb_ipvs_service_get_port,
                    MRB_ARGS_NONE());
  mrb_define_method(mrb, _class_ipvs_service, "proto",
                    mrb_ipvs_service_get_proto, MRB_ARGS_NONE());
  mrb_define_method(mrb, _class_ipvs_service, "sched_name",
                    mrb_ipvs_service_get_sched_name, MRB_ARGS_NONE());
  //  mrb_define_method(mrb, _class_ipvs_service, "timeout",
  //  mrb_ipvs_service_get_timeout, MRB_ARGS_NONE());
  //  mrb_define_method(mrb, _class_ipvs_service, "netmask",
  //  mrb_ipvs_service_get_netmask, MRB_ARGS_NONE());
  //  mrb_define_method(mrb, _class_ipvs_service, "ops",
  //  mrb_ipvs_service_get_ops, MRB_ARGS_NONE());
}
Ejemplo n.º 29
0
void mrb_Git_Buf_init(mrb_state* mrb) {
  static int initialized = 0;
  if (initialized) return;
  else initialized = 1;

  struct RClass* Buf_class = mrb_define_class_under(mrb, Git_module(mrb), "Buf", mrb->object_class);
  MRB_SET_INSTANCE_TT(Buf_class, MRB_TT_DATA);

  mrb_define_method(mrb, Buf_class, "initialize", mrb_Git_Buf_initialize, MRB_ARGS_NONE());
  mrb_define_method(mrb, Buf_class, "to_s", mrb_Git_Buf_to_s, MRB_ARGS_ARG(0, 0));
  mrb_define_method(mrb, Buf_class, "to_str", mrb_Git_Buf_to_s, MRB_ARGS_ARG(0, 0));
  mrb_define_method(mrb, Buf_class, "replace", mrb_Git_Buf_replace, MRB_ARGS_ARG(1, 0));
}
Ejemplo n.º 30
0
void
mrb_setup_arduino() {
  mrb = mrb_open();
  if (mrb == NULL)
    Serial.println("Invalid mrb interpreter, IAS won't work!");
  else
    print_hint();

  cxt = mrbc_context_new(mrb);
  cxt->capture_errors = 1;
  ai = mrb_gc_arena_save(mrb);

  krn = mrb->kernel_module;
  mrb_define_method(mrb, krn, "p", my_p, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, krn, "print", my_print, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, krn, "puts", my_puts, MRB_ARGS_REQ(1));

  led = mrb_define_class(mrb, "Led", mrb->object_class);
  mrb_define_class_method(mrb, led, "high!", mrb_led_high, MRB_ARGS_NONE());
  mrb_define_class_method(mrb, led, "low!", mrb_led_low, MRB_ARGS_NONE());
  mrb_define_class_method(mrb, led, "blink", mrb_led_blink, MRB_ARGS_NONE());
}