Commit ef4f29be authored by ksss's avatar ksss

support class define in singleton class

parent 4a6650b1
......@@ -227,6 +227,7 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
}
switch (mrb_type(outer)) {
case MRB_TT_CLASS:
case MRB_TT_SCLASS:
case MRB_TT_MODULE:
break;
default:
......@@ -1245,21 +1246,31 @@ mrb_class_path(mrb_state *mrb, struct RClass *c)
{
mrb_value path;
const char *name;
mrb_int len;
mrb_sym classpath = mrb_intern_lit(mrb, "__classpath__");
path = mrb_obj_iv_get(mrb, (struct RObject*)c, classpath);
if (mrb_nil_p(path)) {
struct RClass *outer = mrb_class_outer_module(mrb, c);
mrb_sym sym = mrb_class_sym(mrb, c, outer);
mrb_int len;
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_lit(mrb, "::"));
path = mrb_str_buf_new(mrb, 0);
if (mrb_nil_p(base)) {
mrb_str_cat_lit(mrb, path, "#<Class:");
mrb_str_concat(mrb, path, mrb_ptr_to_str(mrb, outer));
mrb_str_cat_lit(mrb, path, ">");
}
else {
mrb_str_concat(mrb, path, base);
}
mrb_str_cat_lit(mrb, path, "::");
name = mrb_sym2name_len(mrb, sym, &len);
mrb_str_concat(mrb, path, mrb_str_new(mrb, name, len));
mrb_str_cat(mrb, path, name, len);
}
else {
name = mrb_sym2name_len(mrb, sym, &len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment