static mrb_value method_call(mrb_state *mrb, mrb_value self) { mrb_value proc = mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "proc")); mrb_value name = mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "@name")); mrb_value recv = mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "@recv")); struct RClass *owner = mrb_class_ptr(mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "@owner"))); mrb_int argc; mrb_value *argv, ret, block; mrb_sym orig_mid; mrb_get_args(mrb, "*&", &argv, &argc, &block); orig_mid = mrb->c->ci->mid; mrb->c->ci->mid = mrb_symbol(name); if (mrb_nil_p(proc)) { mrb_value missing_argv = mrb_ary_new_from_values(mrb, argc, argv); mrb_ary_unshift(mrb, missing_argv, name); ret = mrb_funcall_argv(mrb, recv, mrb_intern_lit(mrb, "method_missing"), argc + 1, RARRAY_PTR(missing_argv)); } else if (!mrb_nil_p(block)) { /* workaround since `mrb_yield_with_class` does not support passing block as parameter need new API that initializes `mrb->c->stack[argc+1]` with block passed by argument */ ret = mrb_funcall_with_block(mrb, recv, mrb_symbol(name), argc, argv, block); } else { ret = mrb_yield_with_class(mrb, proc, argc, argv, recv, owner); } mrb->c->ci->mid = orig_mid; return ret; }
static mrb_value sym_cmp(mrb_state *mrb, mrb_value s1) { mrb_value s2; mrb_sym sym1, sym2; mrb_get_args(mrb, "o", &s2); if (mrb_type(s2) != MRB_TT_SYMBOL) return mrb_nil_value(); sym1 = mrb_symbol(s1); sym2 = mrb_symbol(s2); if (sym1 == sym2) return mrb_fixnum_value(0); else { const char *p1, *p2; int retval; mrb_int len, len1, len2; p1 = mrb_sym2name_len(mrb, sym1, &len1); p2 = mrb_sym2name_len(mrb, sym2, &len2); len = lesser(len1, len2); retval = memcmp(p1, p2, len); if (retval == 0) { if (len1 == len2) return mrb_fixnum_value(0); if (len1 > len2) return mrb_fixnum_value(1); return mrb_fixnum_value(-1); } if (retval > 0) return mrb_fixnum_value(1); return mrb_fixnum_value(-1); } }
mrb_value mrb_mod_const_defined(mrb_state *mrb, mrb_value mod) { mrb_value id; mrb_bool const_defined_p; id = get_sym_or_str_arg(mrb); if (mrb_type(id) == MRB_TT_SYMBOL) { check_const_name_sym(mrb, mrb_symbol(id)); const_defined_p = mrb_const_defined(mrb, mod, mrb_symbol(id)); } else { mrb_value sym; check_const_name_str(mrb, id); sym = mrb_check_intern_str(mrb, id); if (mrb_nil_p(sym)) { const_defined_p = FALSE; } else { const_defined_p = mrb_const_defined(mrb, mod, mrb_symbol(sym)); } } return mrb_bool_value(const_defined_p); }
static mrb_value method_eql(mrb_state *mrb, mrb_value self) { mrb_value other, receiver, orig_proc, other_proc; struct RClass *owner, *klass; struct RProc *orig_rproc, *other_rproc; mrb_get_args(mrb, "o", &other); if (!mrb_obj_is_instance_of(mrb, other, mrb_class(mrb, self))) return mrb_false_value(); if (mrb_class(mrb, self) != mrb_class(mrb, other)) return mrb_false_value(); klass = mrb_class_ptr(IV_GET(self, "@klass")); if (klass != mrb_class_ptr(IV_GET(other, "@klass"))) return mrb_false_value(); owner = mrb_class_ptr(IV_GET(self, "@owner")); if (owner != mrb_class_ptr(IV_GET(other, "@owner"))) return mrb_false_value(); receiver = IV_GET(self, "@recv"); if (!mrb_obj_equal(mrb, receiver, IV_GET(other, "@recv"))) return mrb_false_value(); orig_proc = IV_GET(self, "proc"); other_proc = IV_GET(other, "proc"); if (mrb_nil_p(orig_proc) && mrb_nil_p(other_proc)) { if (mrb_symbol(IV_GET(self, "@name")) == mrb_symbol(IV_GET(other, "@name"))) return mrb_true_value(); else return mrb_false_value(); } if (mrb_nil_p(orig_proc)) return mrb_false_value(); if (mrb_nil_p(other_proc)) return mrb_false_value(); orig_rproc = mrb_proc_ptr(orig_proc); other_rproc = mrb_proc_ptr(other_proc); if (MRB_PROC_CFUNC_P(orig_rproc)) { if (!MRB_PROC_CFUNC_P(other_rproc)) return mrb_false_value(); if (orig_rproc->body.func != other_rproc->body.func) return mrb_false_value(); } else { if (MRB_PROC_CFUNC_P(other_rproc)) return mrb_false_value(); if (orig_rproc->body.irep != other_rproc->body.irep) return mrb_false_value(); } return mrb_true_value(); }
mrb_value mrb_mod_alias(mrb_state *mrb, mrb_value mod) { struct RClass *c = mrb_class_ptr(mod); mrb_value new_value, old_value; mrb_get_args(mrb, "oo", &new_value, &old_value); mrb_alias_method(mrb, c, mrb_symbol(new_value), mrb_symbol(old_value)); return mrb_nil_value(); }
/* * call-seq: * sym.length -> integer * * Same as <code>sym.to_s.length</code>. */ static mrb_value mrb_sym_length(mrb_state *mrb, mrb_value self) { mrb_int len; #ifdef MRB_UTF8_STRING mrb_int byte_len; const char *name = mrb_sym2name_len(mrb, mrb_symbol(self), &byte_len); len = mrb_utf8_len(name, byte_len); #else mrb_sym2name_len(mrb, mrb_symbol(self), &len); #endif return mrb_fixnum_value(len); }
static mrb_value mrb_thread_init(mrb_state* mrb, mrb_value self) { mrb_value proc = mrb_nil_value(); mrb_int argc; mrb_value* argv; mrb_get_args(mrb, "&*", &proc, &argv, &argc); if (!mrb_nil_p(proc) && MRB_PROC_CFUNC_P(mrb_proc_ptr(proc))) { mrb_raise(mrb, E_RUNTIME_ERROR, "forking C defined block"); } if (!mrb_nil_p(proc)) { int i, l; mrb_thread_context* context = (mrb_thread_context*) malloc(sizeof(mrb_thread_context)); context->mrb_caller = mrb; context->mrb = mrb_open_allocf(mrb->allocf, mrb->allocf_ud); migrate_all_symbols(mrb, context->mrb); context->proc = mrb_proc_new(mrb, mrb_proc_ptr(proc)->body.irep); context->proc->target_class = context->mrb->object_class; context->argc = argc; context->argv = calloc(sizeof (mrb_value), context->argc); context->result = mrb_nil_value(); context->alive = TRUE; for (i = 0; i < context->argc; i++) { context->argv[i] = migrate_simple_value(mrb, argv[i], context->mrb); } { mrb_value gv = mrb_funcall(mrb, self, "global_variables", 0, NULL); l = RARRAY_LEN(gv); for (i = 0; i < l; i++) { mrb_int len; int ai = mrb_gc_arena_save(mrb); mrb_value k = mrb_ary_entry(gv, i); mrb_value o = mrb_gv_get(mrb, mrb_symbol(k)); if (is_safe_migratable_simple_value(mrb, o, context->mrb)) { const char *p = mrb_sym2name_len(mrb, mrb_symbol(k), &len); mrb_gv_set(context->mrb, mrb_intern_static(context->mrb, p, len), migrate_simple_value(mrb, o, context->mrb)); } mrb_gc_arena_restore(mrb, ai); } } mrb_iv_set(mrb, self, mrb_intern_lit(mrb, "context"), mrb_obj_value( Data_Wrap_Struct(mrb, mrb->object_class, &mrb_thread_context_type, (void*) context))); pthread_create(&context->thread, NULL, &mrb_thread_func, (void*) context); } return self; }
bool rubyval_to_ccvaluemapintkey(mrb_state* mrb, mrb_value arg, cocos2d::ValueMapIntKey* ret, const char* funcName) { if (! mrb_hash_p(arg)) { return false; } mrb_value key_arr = mrb_hash_keys(mrb, arg); mrb_int len = mrb_ary_len(mrb, key_arr); ValueMapIntKey& dict = *ret; for (mrb_int i = 0; i < len; i++) { mrb_value hk = mrb_ary_ref(mrb, key_arr, i); mrb_value hv = mrb_hash_get(mrb, arg, hk); int int_key = 0; if (mrb_string_p(hk)) { char *kstr = mrb_str_to_cstr(mrb, hk); int_key = atoi(kstr); } else if (mrb_symbol_p(hk)) { mrb_sym sym = mrb_symbol(hk); const char* kstr = mrb_sym2name(mrb, sym); int_key = atoi(kstr); } else { return false; } Value val; if (! rubyval_to_ccvalue(mrb, hv, &val)) { return false; } dict[int_key] = val; } return true; }
bool rubyval_to_dictionary(mrb_state* mrb, mrb_value arg, __Dictionary** outValue, const char* funcName) { if (! mrb_hash_p(arg)) { return false; } mrb_value key_arr = mrb_hash_keys(mrb, arg); mrb_int len = mrb_ary_len(mrb, key_arr); __Dictionary* dic = __Dictionary::create(); for (mrb_int i = 0; i < len; i++) { mrb_value hk = mrb_ary_ref(mrb, key_arr, i); mrb_value hv = mrb_hash_get(mrb, arg, hk); if (mrb_string_p(hk)) { char *kstr = mrb_str_to_cstr(mrb, hk); Ref* ref = to_ref_value(mrb, hv); dic->setObject(ref, std::string(kstr)); } else if (mrb_symbol_p(hk)) { mrb_sym sym = mrb_symbol(hk); const char* kstr = mrb_sym2name(mrb, sym); Ref* ref = to_ref_value(mrb, hv); dic->setObject(ref, std::string(kstr)); } else { CCASSERT(false, "not supported key value type"); } } *outValue = dic; return true; }
/* * call-seq: * sym.length -> integer * * Same as <code>sym.to_s.length</code>. */ static mrb_value mrb_sym_length(mrb_state *mrb, mrb_value self) { mrb_int len; mrb_sym2name_len(mrb, mrb_symbol(self), &len); return mrb_fixnum_value(len); }
static mrb_value ngx_mrb_var_method_missing(mrb_state *mrb, mrb_value self) { mrb_value name, *a; int alen, c_len; mrb_value s_name; char *c_name; ngx_http_request_t *r; r = ngx_mrb_get_request(); // get var symble from method_missing(sym, *args) mrb_get_args(mrb, "n*", &name, &a, &alen); // name is a symble obj // first init name with mrb_symbol // second get mrb_string with mrb_sym2str s_name = mrb_sym2str(mrb, mrb_symbol(name)); c_name = mrb_str_to_cstr(mrb, s_name); c_len = RSTRING_LEN(s_name); if (c_name[c_len-1] == '=') { return ngx_mrb_var_set(mrb, self, strtok(c_name, "="), a[0], r); } else { return ngx_mrb_var_get(mrb, self, c_name, c_len, r); } }
TMO mrb_timeout_value(mrb_state *mrb, mrb_value tmo) { if (mrb_fixnum_p(tmo)) { return (TMO)mrb_fixnum(tmo); } if (mrb_symbol_p(tmo)) { if (mrb_symbol(tmo) == mrb_intern_lit(mrb, "polling")) { return (TMO)TMO_POL; } if (mrb_symbol(tmo) == mrb_intern_lit(mrb, "forever")) { return (TMO)TMO_FEVR; } } mrb_raisef(mrb, E_TYPE_ERROR, "wrong timeout value (%S)", tmo); }
/* * call-seq: * struct[symbol] -> anObject * struct[fixnum] -> anObject * * Attribute Reference---Returns the value of the instance variable * named by <i>symbol</i>, or indexed (0..length-1) by * <i>fixnum</i>. Will raise <code>NameError</code> if the named * variable does not exist, or <code>IndexError</code> if the index is * out of range. * * Customer = Struct.new(:name, :address, :zip) * joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) * * joe["name"] #=> "Joe Smith" * joe[:name] #=> "Joe Smith" * joe[0] #=> "Joe Smith" */ mrb_value mrb_struct_aref_n(mrb_state *mrb, mrb_value s, mrb_value idx) { mrb_int i; if (mrb_string_p(idx)) { mrb_value sym = mrb_check_intern_str(mrb, idx); if (mrb_nil_p(sym)) { mrb_raisef(mrb, E_INDEX_ERROR, "no member '%S' in struct", idx); } idx = sym; } if (mrb_symbol_p(idx)) { return mrb_struct_aref_id(mrb, s, mrb_symbol(idx)); } i = mrb_fixnum(idx); if (i < 0) i = RSTRUCT_LEN(s) + i; if (i < 0) mrb_raisef(mrb, E_INDEX_ERROR, "offset %S too small for struct(size:%S)", mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s))); if (RSTRUCT_LEN(s) <= i) mrb_raisef(mrb, E_INDEX_ERROR, "offset %S too large for struct(size:%S)", mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s))); return RSTRUCT_PTR(s)[i]; }
static mrb_value read_object(MarshalContext *ctx) { mrb_state *mrb = ctx->mrb; mrb_value class_path = read_value(ctx); struct RClass *klass = mrb_class_from_path(mrb, class_path); mrb_value obj = mrb_obj_value(mrb_obj_alloc(mrb, MRB_TT_OBJECT, klass)); ctx->objects.add(obj); int iv_count = read_fixnum(ctx); int i; for (i = 0; i < iv_count; ++i) { mrb_value iv_name = read_value(ctx); mrb_value iv_value = read_value(ctx); mrb_obj_iv_set(mrb, mrb_obj_ptr(obj), mrb_symbol(iv_name), iv_value); } return obj; }
static mrb_value mrb_struct_aset_sym(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val) { mrb_value members, *ptr; const mrb_value *ptr_members; mrb_int i, len; members = struct_members(mrb, s); len = RARRAY_LEN(members); if (RSTRUCT_LEN(s) != len) { mrb_raisef(mrb, E_TYPE_ERROR, "struct size differs (%S required %S given)", mrb_fixnum_value(len), mrb_fixnum_value(RSTRUCT_LEN(s))); } ptr = RSTRUCT_PTR(s); ptr_members = RARRAY_PTR(members); for (i=0; i<len; i++) { if (mrb_symbol(ptr_members[i]) == id) { ptr[i] = val; return val; } } mrb_name_error(mrb, id, "no member '%S' in struct", mrb_sym2str(mrb, id)); return val; /* not reach */ }
static mrb_value mrb_struct_set(mrb_state *mrb, mrb_value obj, mrb_value val) { const char *name; size_t i, len; mrb_int slen; mrb_sym mid; mrb_value members, slot, *ptr, *ptr_members; /* get base id */ name = mrb_sym2name_len(mrb, mrb->c->ci->mid, &slen); mid = mrb_intern(mrb, name, slen-1); /* omit last "=" */ members = mrb_struct_members(mrb, obj); ptr_members = RARRAY_PTR(members); len = RARRAY_LEN(members); ptr = RSTRUCT_PTR(obj); for (i=0; i<len; i++) { slot = ptr_members[i]; if (mrb_symbol(slot) == mid) { return ptr[i] = val; } } mrb_raisef(mrb, E_INDEX_ERROR, "`%S' is not a struct member", mrb_sym2str(mrb, mid)); return mrb_nil_value(); /* not reached */ }
static mrb_value mrb_struct_aset(mrb_state *mrb, mrb_value s) { mrb_int i; mrb_value idx; mrb_value val; mrb_get_args(mrb, "oo", &idx, &val); if (mrb_string_p(idx)) { mrb_value sym = mrb_check_intern_str(mrb, idx); if (mrb_nil_p(sym)) { mrb_name_error(mrb, mrb_intern_str(mrb, idx), "no member '%S' in struct", idx); } idx = sym; } if (mrb_symbol_p(idx)) { return mrb_struct_aset_sym(mrb, s, mrb_symbol(idx), val); } i = mrb_int(mrb, idx); if (i < 0) i = RSTRUCT_LEN(s) + i; if (i < 0) { mrb_raisef(mrb, E_INDEX_ERROR, "offset %S too small for struct(size:%S)", mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s))); } if (RSTRUCT_LEN(s) <= i) { mrb_raisef(mrb, E_INDEX_ERROR, "offset %S too large for struct(size:%S)", mrb_fixnum_value(i), mrb_fixnum_value(RSTRUCT_LEN(s))); } return RSTRUCT_PTR(s)[i] = val; }
/* * call-seq: * obj.method_missing(symbol [, *args] ) -> result * * Invoked by Ruby when <i>obj</i> is sent a message it cannot handle. * <i>symbol</i> is the symbol for the method called, and <i>args</i> * are any arguments that were passed to it. By default, the interpreter * raises an error when this method is called. However, it is possible * to override the method to provide more dynamic behavior. * If it is decided that a particular method should not be handled, then * <i>super</i> should be called, so that ancestors can pick up the * missing method. * The example below creates * a class <code>Roman</code>, which responds to methods with names * consisting of roman numerals, returning the corresponding integer * values. * * class Roman * def romanToInt(str) * # ... * end * def method_missing(methId) * str = methId.id2name * romanToInt(str) * end * end * * r = Roman.new * r.iv #=> 4 * r.xxiii #=> 23 * r.mm #=> 2000 */ static mrb_value mrb_bob_missing(mrb_state *mrb, mrb_value mod) { mrb_value name, *a; int alen; mrb_value inspect; mrb_get_args(mrb, "o*", &name, &a, &alen); if (!mrb_symbol_p(name)) { mrb_raise(mrb, E_TYPE_ERROR, "name should be a symbol"); } if (mrb_respond_to(mrb,mod,mrb_intern2(mrb,"inspect",7))){ inspect = mrb_funcall(mrb, mod, "inspect", 0); if (RSTRING_LEN(inspect) > 64) { inspect = mrb_any_to_s(mrb, mod); } } else { inspect = mrb_any_to_s(mrb, mod); } mrb_raisef(mrb, E_NOMETHOD_ERROR, "undefined method '%S' for %S", mrb_sym2str(mrb, mrb_symbol(name)), inspect); /* not reached */ return mrb_nil_value(); }
static int trap_signm(mrb_state *mrb, mrb_value vsig) { int sig = -1; const char *s; switch (mrb_type(vsig)) { case MRB_TT_FIXNUM: sig = mrb_fixnum(vsig); if (sig < 0 || sig >= NSIG) { mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid signal number (%S)", vsig); } break; case MRB_TT_SYMBOL: s = mrb_sym2name(mrb, mrb_symbol(vsig)); if (!s) mrb_raise(mrb, E_ARGUMENT_ERROR, "bad signal"); goto str_signal; default: vsig = mrb_string_type(mrb, vsig); s = RSTRING_PTR(vsig); str_signal: if (memcmp("SIG", s, 3) == 0) s += 3; sig = signm2signo(s); if (sig == 0 && strcmp(s, "EXIT") != 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "unsupported signal"); break; } return sig; }
/* * call-seq: * obj.respond_to?(symbol, include_private=false) -> true or false * * Returns +true+ if _obj_ responds to the given * method. Private methods are included in the search only if the * optional second parameter evaluates to +true+. * * If the method is not implemented, * as Process.fork on Windows, File.lchmod on GNU/Linux, etc., * false is returned. * * If the method is not defined, <code>respond_to_missing?</code> * method is called and the result is returned. */ mrb_value obj_respond_to(mrb_state *mrb, mrb_value self) { mrb_value *argv; int argc; mrb_value mid, priv; mrb_sym id, rtm_id; mrb_bool respond_to_p = TRUE; mrb_get_args(mrb, "*", &argv, &argc); mid = argv[0]; if (argc > 1) priv = argv[1]; else priv = mrb_nil_value(); if (mrb_symbol_p(mid)) { id = mrb_symbol(mid); } else { mrb_value tmp; if (!mrb_string_p(mid)) { tmp = mrb_check_string_type(mrb, mid); if (mrb_nil_p(tmp)) { tmp = mrb_inspect(mrb, mid); mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a symbol", tmp); } } tmp = mrb_check_intern_str(mrb, mid); if (mrb_nil_p(tmp)) { respond_to_p = FALSE; } else { id = mrb_symbol(tmp); } } if (respond_to_p) { respond_to_p = basic_obj_respond_to(mrb, self, id, !mrb_test(priv)); } if (!respond_to_p) { rtm_id = mrb_intern2(mrb, "respond_to_missing?", 19); if (basic_obj_respond_to(mrb, self, rtm_id, !mrb_test(priv))) { return mrb_funcall_argv(mrb, self, rtm_id, argc, argv); } } return mrb_bool_value(respond_to_p); }
int mrb_class_defined(mrb_state *mrb, const char *name) { mrb_value sym = mrb_check_intern_cstr(mrb, name); if (mrb_nil_p(sym)) { return FALSE; } return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), mrb_symbol(sym)); }
Ref* to_ref_value(mrb_state* mrb, mrb_value val) { switch (val.tt) { case mrb_vtype::MRB_TT_FIXNUM: { mrb_int v = mrb_fixnum(val); return Integer::create((int)v); } case mrb_vtype::MRB_TT_FLOAT: { mrb_float v = mrb_float(val); return Double::create((double)v); } case mrb_vtype::MRB_TT_FALSE: case mrb_vtype::MRB_TT_TRUE: { return Bool::create(mrb_bool(val)); } case mrb_vtype::MRB_TT_STRING: { char* str = mrb_str_to_cstr(mrb, val); return String::createWithFormat("%s", str); } case mrb_vtype::MRB_TT_SYMBOL: { mrb_sym sym = mrb_symbol(val); const char* str = mrb_sym2name(mrb, sym); return String::createWithFormat("%s", str); } case mrb_vtype::MRB_TT_RANGE: { // TODO: range /* mrb_int beg; mrb_int len; mrb_range_beg_len(mrb, val, &beg, &len, 0); */ break; } case mrb_vtype::MRB_TT_OBJECT: { // TODO: ruby object break; } case mrb_vtype::MRB_TT_DATA: { Ref* ref =static_cast<Ref*>(mrb_get_datatype(mrb, val, &ruby_cocos2dx_Ref_type)); return ref; } case mrb_vtype::MRB_TT_UNDEF: break; default: CCASSERT(false, "not supported type"); } return nullptr; }
/* * call-seq: * sym.id2name -> string * sym.to_s -> string * * Returns the name or string corresponding to <i>sym</i>. * * :fred.id2name #=> "fred" */ static mrb_value mrb_sym_to_s(mrb_state *mrb, mrb_value sym) { mrb_sym id = mrb_symbol(sym); const char *p; mrb_int len; p = mrb_sym2name_len(mrb, id, &len); return mrb_str_new_static(mrb, p, len); }
static mrb_value mrb_mod_method_defined(mrb_state *mrb, mrb_value mod) { mrb_value id; mrb_bool method_defined_p; id = get_sym_or_str_arg(mrb); if (mrb_symbol_p(id)) { method_defined_p = mrb_obj_respond_to(mrb_class_ptr(mod), mrb_symbol(id)); } else { mrb_value sym = mrb_check_intern_str(mrb, id); if (mrb_nil_p(sym)) { method_defined_p = FALSE; } else { method_defined_p = mrb_obj_respond_to(mrb_class_ptr(mod), mrb_symbol(sym)); } } return mrb_bool_value(method_defined_p); }
MRB_API mrb_bool mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2) { if (mrb_type(v1) != mrb_type(v2)) return FALSE; switch (mrb_type(v1)) { case MRB_TT_TRUE: return TRUE; case MRB_TT_FALSE: case MRB_TT_FIXNUM: return (mrb_fixnum(v1) == mrb_fixnum(v2)); case MRB_TT_SYMBOL: return (mrb_symbol(v1) == mrb_symbol(v2)); case MRB_TT_FLOAT: return (mrb_float(v1) == mrb_float(v2)); default: return (mrb_ptr(v1) == mrb_ptr(v2)); } }
static int32_t compare_break_method( mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc ) { const char* class_name; const char* method_name; struct RProc* m; struct RClass* sc; const char* sn; mrb_sym ssym; mrb_debug_methodpoint *method_p; mrb_bool is_defined; method_name = mrb_sym2name(mrb, method_sym); method_p = &bp->point.methodpoint; if(strcmp(method_p->method_name, method_name) == 0) { class_name = get_class_name(mrb, class_obj); if(class_name == NULL) { if(method_p->class_name == NULL) { return bp->bpno; } } else if(method_p->class_name != NULL) { m = mrb_method_search_vm(mrb, &class_obj, method_sym); if(m == NULL) { return MRB_DEBUG_OK; } if(MRB_PROC_CFUNC_P(m)) { *isCfunc = TRUE; } is_defined = mrb_class_defined(mrb, method_p->class_name); if(is_defined == FALSE) { return MRB_DEBUG_OK; } sc = mrb_class_get(mrb, method_p->class_name); ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name)); m = mrb_method_search_vm(mrb, &sc, ssym); if(m == NULL) { return MRB_DEBUG_OK; } class_name = get_class_name(mrb, class_obj); sn = get_class_name(mrb, sc); if(strcmp(sn, class_name) == 0) { return bp->bpno; } } } return MRB_DEBUG_OK; }
static sighandler_t trap_handler(mrb_state *mrb, mrb_value *cmd, int sig) { sighandler_t func = sighandler; mrb_value command; if (mrb_nil_p(*cmd)) { func = SIG_IGN; } else { command = *cmd; if (mrb_type(command) == MRB_TT_SYMBOL) { command = mrb_sym2str(mrb, mrb_symbol(command)); if (mrb_undef_p(command)) mrb_raise(mrb, E_ARGUMENT_ERROR, "bad handler"); } if (mrb_string_p(command)) { *cmd = command; switch (RSTRING_LEN(command)) { case 0: goto sig_ign; break; case 6: if (memcmp(RSTRING_PTR(command), "IGNORE", 6) == 0) { goto sig_ign; } break; case 7: if (memcmp(RSTRING_PTR(command), "SIG_IGN", 7) == 0) { sig_ign: func = SIG_IGN; *cmd = mrb_true_value(); } else if (memcmp(RSTRING_PTR(command), "SIG_DFL", 7) == 0) { sig_dfl: func = default_handler(sig); *cmd = mrb_true_value(); } else if (memcmp(RSTRING_PTR(command), "DEFAULT", 7) == 0) { goto sig_dfl; } break; case 4: if (memcmp(RSTRING_PTR(command), "EXIT", 4) == 0) { *cmd = mrb_undef_value(); } break; } } } return func; }
static mrb_sym mrb_sym_value(mrb_state *mrb, mrb_value val) { if(val.tt == MRB_TT_STRING) { return mrb_intern(mrb, RSTRING_PTR(val)); } else if(val.tt != MRB_TT_SYMBOL) { mrb_value obj = mrb_funcall(mrb, val, "inspect", 0); mrb_raise(mrb, E_TYPE_ERROR, "%s is not a symbol", mrb_string_value_ptr(mrb, obj)); } return mrb_symbol(val); }
static mrb_sym mrb_sym_value(mrb_state *mrb, mrb_value val) { if (mrb_string_p(val)) { return mrb_intern_str(mrb, val); } else if(!mrb_symbol_p(val)) { mrb_value obj = mrb_funcall(mrb, val, "inspect", 0); mrb_raisef(mrb, E_TYPE_ERROR, "%s is not a symbol", mrb_string_value_ptr(mrb, obj)); } return mrb_symbol(val); }
mrb_value mrb_mod_remove_method(mrb_state *mrb, mrb_value mod) { int argc; mrb_value *argv; mrb_get_args(mrb, "*", &argv, &argc); while (argc--) { remove_method(mrb, mod, mrb_symbol(*argv)); argv++; } return mod; }