예제 #1
0
파일: object.c 프로젝트: lemonhall/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_undef_class_method(mrb, n, "new");
  mrb_define_method(mrb, n, "&",    false_and,      MRB_ARGS_REQ(1));  /* 15.2.4.3.1  */
  mrb_define_method(mrb, n, "^",    false_xor,      MRB_ARGS_REQ(1));  /* 15.2.4.3.2  */
  mrb_define_method(mrb, n, "|",    false_or,       MRB_ARGS_REQ(1));  /* 15.2.4.3.3  */
  mrb_define_method(mrb, n, "nil?", mrb_true,       MRB_ARGS_NONE());  /* 15.2.4.3.4  */
  mrb_define_method(mrb, n, "to_s", nil_to_s,       MRB_ARGS_NONE());  /* 15.2.4.3.5  */
  mrb_define_method(mrb, n, "inspect", nil_inspect, MRB_ARGS_NONE());

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

  f = mrb->false_class = mrb_define_class(mrb, "FalseClass", mrb->object_class);
  mrb_undef_class_method(mrb, f, "new");
  mrb_define_method(mrb, f, "&",    false_and,      MRB_ARGS_REQ(1));  /* 15.2.6.3.1  */
  mrb_define_method(mrb, f, "^",    false_xor,      MRB_ARGS_REQ(1));  /* 15.2.6.3.2  */
  mrb_define_method(mrb, f, "to_s", false_to_s,     MRB_ARGS_NONE());  /* 15.2.6.3.3  */
  mrb_define_method(mrb, f, "|",    false_or,       MRB_ARGS_REQ(1));  /* 15.2.6.3.4  */
  mrb_define_method(mrb, f, "inspect", false_to_s,  MRB_ARGS_NONE());
}
예제 #2
0
파일: method.c 프로젝트: chasonr/mruby
void
mrb_mruby_method_gem_init(mrb_state* mrb)
{
  struct RClass *unbound_method = mrb_define_class(mrb, "UnboundMethod", mrb->object_class);
  struct RClass *method = mrb_define_class(mrb, "Method", mrb->object_class);

  mrb_undef_class_method(mrb, unbound_method, "new");
  mrb_define_method(mrb, unbound_method, "bind", unbound_method_bind, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, unbound_method, "super_method", method_super_method, MRB_ARGS_NONE());
  mrb_define_method(mrb, unbound_method, "==", method_eql, MRB_ARGS_REQ(1));
  mrb_alias_method(mrb, unbound_method, mrb_intern_lit(mrb, "eql?"), mrb_intern_lit(mrb, "=="));
  mrb_define_method(mrb, unbound_method, "to_s", method_to_s, MRB_ARGS_NONE());
  mrb_define_method(mrb, unbound_method, "inspect", method_to_s, MRB_ARGS_NONE());
  mrb_define_method(mrb, unbound_method, "arity", method_arity, MRB_ARGS_NONE());
  mrb_define_method(mrb, unbound_method, "source_location", method_source_location, MRB_ARGS_NONE());
  mrb_define_method(mrb, unbound_method, "parameters", method_parameters, MRB_ARGS_NONE());

  mrb_undef_class_method(mrb, method, "new");
  mrb_define_method(mrb, method, "==", method_eql, MRB_ARGS_REQ(1));
  mrb_alias_method(mrb, method, mrb_intern_lit(mrb, "eql?"), mrb_intern_lit(mrb, "=="));
  mrb_define_method(mrb, method, "to_s", method_to_s, MRB_ARGS_NONE());
  mrb_define_method(mrb, method, "inspect", method_to_s, MRB_ARGS_NONE());
  mrb_define_method(mrb, method, "call", method_call, MRB_ARGS_ANY());
  mrb_alias_method(mrb, method, mrb_intern_lit(mrb, "[]"), mrb_intern_lit(mrb, "call"));
  mrb_define_method(mrb, method, "unbind", method_unbind, MRB_ARGS_NONE());
  mrb_define_method(mrb, method, "super_method", method_super_method, MRB_ARGS_NONE());
  mrb_define_method(mrb, method, "arity", method_arity, MRB_ARGS_NONE());
  mrb_define_method(mrb, method, "source_location", method_source_location, MRB_ARGS_NONE());
  mrb_define_method(mrb, method, "parameters", method_parameters, MRB_ARGS_NONE());

  mrb_define_method(mrb, mrb->kernel_module, "method", mrb_kernel_method, MRB_ARGS_REQ(1));

  mrb_define_method(mrb, mrb->module_class, "instance_method", mrb_module_instance_method, MRB_ARGS_REQ(1));
}
예제 #3
0
파일: numeric.c 프로젝트: EasyRPG/mruby
/* ------------------------------------------------------------------------*/
void
mrb_init_numeric(mrb_state *mrb)
{
  struct RClass *numeric, *integer, *fixnum, *fl;

  /* Numeric Class */
  numeric = mrb_define_class(mrb, "Numeric",  mrb->object_class);

  mrb_define_method(mrb, numeric, "**",       num_pow,        MRB_ARGS_REQ(1));
  mrb_define_method(mrb, numeric, "/",        num_div,        MRB_ARGS_REQ(1));  /* 15.2.8.3.4  */
  mrb_define_method(mrb, numeric, "quo",      num_div,        MRB_ARGS_REQ(1));  /* 15.2.7.4.5 (x) */
  mrb_define_method(mrb, numeric, "<=>",      num_cmp,        MRB_ARGS_REQ(1));  /* 15.2.9.3.6  */

  /* Integer Class */
  integer = mrb_define_class(mrb, "Integer",  numeric);
  mrb_undef_class_method(mrb, integer, "new");
  mrb_define_method(mrb, integer, "to_i", int_to_i, MRB_ARGS_NONE());              /* 15.2.8.3.24 */
  mrb_define_method(mrb, integer, "to_int", int_to_i, MRB_ARGS_NONE());

  fixnum = mrb->fixnum_class = mrb_define_class(mrb, "Fixnum", integer);
  mrb_define_method(mrb, fixnum,  "+",        fix_plus,          MRB_ARGS_REQ(1)); /* 15.2.8.3.1  */
  mrb_define_method(mrb, fixnum,  "-",        fix_minus,         MRB_ARGS_REQ(1)); /* 15.2.8.3.2  */
  mrb_define_method(mrb, fixnum,  "*",        fix_mul,           MRB_ARGS_REQ(1)); /* 15.2.8.3.3  */
  mrb_define_method(mrb, fixnum,  "%",        fix_mod,           MRB_ARGS_REQ(1)); /* 15.2.8.3.5  */
  mrb_define_method(mrb, fixnum,  "==",       fix_equal,         MRB_ARGS_REQ(1)); /* 15.2.8.3.7  */
  mrb_define_method(mrb, fixnum,  "~",        fix_rev,           MRB_ARGS_NONE()); /* 15.2.8.3.8  */
  mrb_define_method(mrb, fixnum,  "&",        fix_and,           MRB_ARGS_REQ(1)); /* 15.2.8.3.9  */
  mrb_define_method(mrb, fixnum,  "|",        fix_or,            MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */
  mrb_define_method(mrb, fixnum,  "^",        fix_xor,           MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */
  mrb_define_method(mrb, fixnum,  "<<",       fix_lshift,        MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */
  mrb_define_method(mrb, fixnum,  ">>",       fix_rshift,        MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */
  mrb_define_method(mrb, fixnum,  "eql?",     num_eql,           MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */
  mrb_define_method(mrb, fixnum,  "hash",     flo_hash,          MRB_ARGS_NONE()); /* 15.2.8.3.18 */
  mrb_define_method(mrb, fixnum,  "to_f",     fix_to_f,          MRB_ARGS_NONE()); /* 15.2.8.3.23 */
  mrb_define_method(mrb, fixnum,  "to_s",     fix_to_s,          MRB_ARGS_NONE()); /* 15.2.8.3.25 */
  mrb_define_method(mrb, fixnum,  "inspect",  fix_to_s,          MRB_ARGS_NONE());
  mrb_define_method(mrb, fixnum,  "divmod",   fix_divmod,        MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */

  /* Float Class */
  fl = mrb->float_class = mrb_define_class(mrb, "Float", numeric);
  mrb_undef_class_method(mrb,  fl, "new");
  mrb_define_method(mrb, fl,      "+",         flo_plus,         MRB_ARGS_REQ(1)); /* 15.2.9.3.1  */
  mrb_define_method(mrb, fl,      "-",         flo_minus,        MRB_ARGS_REQ(1)); /* 15.2.9.3.2  */
  mrb_define_method(mrb, fl,      "*",         flo_mul,          MRB_ARGS_REQ(1)); /* 15.2.9.3.3  */
  mrb_define_method(mrb, fl,      "%",         flo_mod,          MRB_ARGS_REQ(1)); /* 15.2.9.3.5  */
  mrb_define_method(mrb, fl,      "==",        flo_eq,           MRB_ARGS_REQ(1)); /* 15.2.9.3.7  */
  mrb_define_method(mrb, fl,      "ceil",      flo_ceil,         MRB_ARGS_NONE()); /* 15.2.9.3.8  */
  mrb_define_method(mrb, fl,      "finite?",   flo_finite_p,     MRB_ARGS_NONE()); /* 15.2.9.3.9  */
  mrb_define_method(mrb, fl,      "floor",     flo_floor,        MRB_ARGS_NONE()); /* 15.2.9.3.10 */
  mrb_define_method(mrb, fl,      "infinite?", flo_infinite_p,   MRB_ARGS_NONE()); /* 15.2.9.3.11 */
  mrb_define_method(mrb, fl,      "round",     flo_round,        MRB_ARGS_NONE()); /* 15.2.9.3.12 */
  mrb_define_method(mrb, fl,      "to_f",      flo_to_f,         MRB_ARGS_NONE()); /* 15.2.9.3.13 */
  mrb_define_method(mrb, fl,      "to_i",      flo_truncate,     MRB_ARGS_NONE()); /* 15.2.9.3.14 */
  mrb_define_method(mrb, fl,      "to_int",    flo_truncate,     MRB_ARGS_NONE());
  mrb_define_method(mrb, fl,      "truncate",  flo_truncate,     MRB_ARGS_NONE()); /* 15.2.9.3.15 */
  mrb_define_method(mrb, fl,      "divmod",    flo_divmod,       MRB_ARGS_REQ(1));

  mrb_define_method(mrb, fl,      "to_s",      flo_to_s,         MRB_ARGS_NONE()); /* 15.2.9.3.16(x) */
  mrb_define_method(mrb, fl,      "inspect",   flo_to_s,         MRB_ARGS_NONE());
}
예제 #4
0
파일: symbol.c 프로젝트: mruby-Forum/mruby
void
mrb_init_symbol(mrb_state *mrb)
{
  struct RClass *sym;

  mrb->symbol_class = sym = mrb_define_class(mrb, "Symbol", mrb->object_class);  /* 15.2.11 */
  MRB_SET_INSTANCE_TT(sym, MRB_TT_SYMBOL);
  mrb_undef_class_method(mrb,  sym, "new");

  mrb_define_method(mrb, sym, "id2name", sym_to_s,    MRB_ARGS_NONE());          /* 15.2.11.3.2 */
  mrb_define_method(mrb, sym, "to_s",    sym_to_s,    MRB_ARGS_NONE());          /* 15.2.11.3.3 */
  mrb_define_method(mrb, sym, "to_sym",  sym_to_sym,  MRB_ARGS_NONE());          /* 15.2.11.3.4 */
  mrb_define_method(mrb, sym, "inspect", sym_inspect, MRB_ARGS_NONE());          /* 15.2.11.3.5(x) */
  mrb_define_method(mrb, sym, "<=>",     sym_cmp,     MRB_ARGS_REQ(1));
}
예제 #5
0
static mrb_value
mrb_groonga_init(mrb_state *mrb, mrb_value self)
{
  grn_ctx *ctx = mrb->ud;

  mrb_undef_class_method(mrb, ctx->impl->mrb.module, "init");

  mrb_define_class(mrb, "LoadError", mrb_class_get(mrb, "ScriptError"));
  mrb_define_method(mrb, mrb->kernel_module,
                    "load", mrb_kernel_load, MRB_ARGS_REQ(1));

  {
    mrb_value load_path;
    const char *plugins_dir;
    const char *system_ruby_scripts_dir;

    load_path = mrb_ary_new(mrb);
    plugins_dir = grn_plugin_get_system_plugins_dir();
    mrb_ary_push(mrb, load_path,
                 mrb_str_new_cstr(mrb, plugins_dir));
    system_ruby_scripts_dir = grn_mrb_get_system_ruby_scripts_dir(ctx);
    mrb_ary_push(mrb, load_path,
                 mrb_str_new_cstr(mrb, system_ruby_scripts_dir));
    mrb_gv_set(mrb, mrb_intern_cstr(mrb, "$LOAD_PATH"), load_path);
  }

  grn_mrb_load(ctx, "require.rb");
  grn_mrb_load(ctx, "initialize/pre.rb");

  grn_mrb_converter_init(ctx);
  grn_mrb_error_init(ctx);
  grn_mrb_id_init(ctx);
  grn_mrb_operator_init(ctx);
  grn_mrb_command_version_init(ctx);
  grn_mrb_ctx_init(ctx);
  grn_mrb_logger_init(ctx);
  grn_mrb_query_logger_init(ctx);
  grn_mrb_void_init(ctx);
  grn_mrb_bulk_init(ctx);
  grn_mrb_cache_init(ctx);
  grn_mrb_object_init(ctx);
  grn_mrb_object_flags_init(ctx);
  grn_mrb_database_init(ctx);
  grn_mrb_table_init(ctx);
  grn_mrb_array_init(ctx);
  grn_mrb_hash_table_init(ctx);
  grn_mrb_patricia_trie_init(ctx);
  grn_mrb_double_array_trie_init(ctx);
  grn_mrb_table_group_flags_init(ctx);
  grn_mrb_table_group_result_init(ctx);
  grn_mrb_table_sort_flags_init(ctx);
  grn_mrb_table_sort_key_init(ctx);
  grn_mrb_record_init(ctx);
  grn_mrb_column_init(ctx);
  grn_mrb_fixed_size_column_init(ctx);
  grn_mrb_variable_size_column_init(ctx);
  grn_mrb_index_column_init(ctx);
  grn_mrb_index_cursor_init(ctx);
  grn_mrb_type_init(ctx);
  grn_mrb_expr_init(ctx);
  grn_mrb_accessor_init(ctx);
  grn_mrb_procedure_init(ctx);
  grn_mrb_command_init(ctx);
  grn_mrb_command_input_init(ctx);
  grn_mrb_table_cursor_init(ctx);
  grn_mrb_table_cursor_flags_init(ctx);
  grn_mrb_content_type_init(ctx);
  grn_mrb_writer_init(ctx);
  grn_mrb_config_init(ctx);

  grn_mrb_load(ctx, "initialize/post.rb");

  return mrb_nil_value();
}
예제 #6
0
void
mruby_allegro_graphics_init(mrb_state *mrb)
{
  struct RClass *am = M_ALLEGRO;
  struct RClass *cc = mrb_define_class_under(mrb, am, "Color", mrb->object_class);
  struct RClass *bc = mrb_define_class_under(mrb, am, "Bitmap", mrb->object_class);
  MRB_SET_INSTANCE_TT(cc, MRB_TT_DATA);
  MRB_SET_INSTANCE_TT(bc, MRB_TT_DATA);
  mrb_define_method(mrb, cc, "initialize", color_initialize, MRB_ARGS_OPT(1));
  mrb_define_class_method(mrb, cc, "rgb", color_map_rgb, MRB_ARGS_REQ(3));
  mrb_define_class_method(mrb, cc, "rgba", color_map_rgba, MRB_ARGS_REQ(4));
  mrb_define_class_method(mrb, cc, "rgb_f", color_map_rgb_f, MRB_ARGS_REQ(3));
  mrb_define_class_method(mrb, cc, "rgba_f", color_map_rgba_f, MRB_ARGS_REQ(4));
  mrb_define_method(mrb, cc, "rgb", color_unmap_rgb, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "rgb_f", color_unmap_rgb_f, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "rgba", color_unmap_rgba, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "rgba_f", color_unmap_rgba_f, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "inspect", color_inspect, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "r", color_r_getter, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "g", color_g_getter, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "b", color_b_getter, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "a", color_a_getter, MRB_ARGS_NONE());
  mrb_define_method(mrb, cc, "r=", color_r_setter, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, cc, "g=", color_g_setter, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, cc, "b=", color_b_setter, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, cc, "a=", color_a_setter, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, bc, "unlock", bitmap_unlock, MRB_ARGS_NONE());
  mrb_undef_class_method(mrb, bc, "new");
  mrb_define_class_method(mrb, bc, "create", bitmap_create, MRB_ARGS_REQ(2));
  mrb_define_method(mrb, bc, "destroy", bitmap_destroy, MRB_ARGS_NONE());
  mrb_define_method(mrb, bc, "destroyed?", bitmap_destroyed, MRB_ARGS_NONE());
  mrb_define_method(mrb, bc, "height", bitmap_height, MRB_ARGS_NONE());
  mrb_define_method(mrb, bc, "width", bitmap_width, MRB_ARGS_NONE());
  mrb_define_method(mrb, bc, "get_pixel", bitmap_get_pixel, MRB_ARGS_REQ(2));
  mrb_define_method(mrb, bc, "locked?", bitmap_locked, MRB_ARGS_NONE());
  mrb_define_method(mrb, bc, "compatible?", bitmap_compatible, MRB_ARGS_NONE());
  mrb_define_class_method(mrb, am, "clear_to_color", clear_to_color, MRB_ARGS_OPT(1));
  mrb_define_method(mrb, bc, "draw", bitmap_draw, MRB_ARGS_REQ(2) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_tinted", bitmap_draw_tinted, MRB_ARGS_REQ(3) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_region", bitmap_draw_region, MRB_ARGS_REQ(6) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_tinted_region", bitmap_draw_tinted_region, MRB_ARGS_REQ(7) | MRB_ARGS_OPT(2));
  mrb_define_class_method(mrb, am, "draw_pixel", draw_pixel, MRB_ARGS_REQ(3));
  mrb_define_method(mrb, bc, "draw_rotated", bitmap_draw_rotated, MRB_ARGS_REQ(5) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_tinted_rotated", bitmap_draw_tinted_rotated, MRB_ARGS_REQ(6) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_scaled_rotated", bitmap_draw_scaled_rotated, MRB_ARGS_REQ(7) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_tinted_scaled_rotated", bitmap_draw_tinted_scaled_rotated, MRB_ARGS_REQ(8) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_tinted_scaled_rotated_region", bitmap_draw_tinted_scaled_rotated_region, MRB_ARGS_REQ(12) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_scaled", bitmap_draw_scaled, MRB_ARGS_REQ(8) | MRB_ARGS_OPT(2));
  mrb_define_method(mrb, bc, "draw_tinted_scaled", bitmap_draw_tinted_scaled, MRB_ARGS_REQ(9) | MRB_ARGS_OPT(2));
  mrb_define_class_method(mrb, am, "put_pixel", put_pixel, MRB_ARGS_REQ(3));
  mrb_define_class_method(mrb, am, "put_blended_pixel", put_blended_pixel, MRB_ARGS_REQ(3));
  mrb_define_class_method(mrb, am, "target=", target_setter, MRB_ARGS_REQ(1));
  mrb_define_class_method(mrb, C_ALLEGRO_DISPLAY, "current", display_current, MRB_ARGS_NONE());
  mrb_define_class_method(mrb, am, "blender", blender_getter, MRB_ARGS_NONE());
  mrb_define_class_method(mrb, am, "separate_blender", separate_blender_getter, MRB_ARGS_NONE());
  mrb_define_class_method(mrb, am, "blender=", blender_setter, MRB_ARGS_REQ(1));
  mrb_define_class_method(mrb, am, "separate_blender=", separate_blender_setter, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, bc, "convert_mask_to_alpha", convert_mask_to_alpha, MRB_ARGS_REQ(1));
  mrb_define_class_method(mrb, am, "hold_drawing", hold_drawing, MRB_ARGS_REQ(1));
  mrb_define_class_method(mrb, am, "drawing_held?", drawing_held, MRB_ARGS_NONE());
  mrb_define_class_method(mrb, bc, "load", bitmap_load, MRB_ARGS_REQ(1));
  mrb_define_method(mrb, bc, "save", bitmap_save, MRB_ARGS_REQ(1));
}