mrb_value mrb_class_path(mrb_state *mrb, struct RClass *c) { mrb_value path; const char *name; int len; path = mrb_obj_iv_get(mrb, (struct RObject*)c, mrb_intern(mrb, "__classpath__")); if (mrb_nil_p(path)) { struct RClass *outer = mrb_class_outer_module(mrb, c); mrb_sym sym = mrb_class_sym(mrb, c, outer); if (sym == 0) { return mrb_nil_value(); } else if (outer && outer != mrb->object_class) { mrb_value base = mrb_class_path(mrb, outer); path = mrb_str_plus(mrb, base, mrb_str_new(mrb, "::", 2)); name = mrb_sym2name_len(mrb, sym, &len); mrb_str_concat(mrb, path, mrb_str_new(mrb, name, len)); } else { name = mrb_sym2name_len(mrb, sym, &len); path = mrb_str_new(mrb, name, len); } mrb_obj_iv_set(mrb, (struct RObject*)c, mrb_intern(mrb, "__classpath__"), path); } return path; }
static const char* get_class_name( mrb_state *mrb, struct RClass *class_obj ) { struct RClass *outer; mrb_sym class_sym; outer = mrb_class_outer_module(mrb, class_obj); class_sym = mrb_class_sym(mrb, class_obj, outer); return mrb_sym2name(mrb, class_sym); }