type check class/module in mrb_get_args(); close #1477

parent f8fea693
......@@ -380,6 +380,7 @@ to_hash(mrb_state *mrb, mrb_value val)
string mruby type C type note
----------------------------------------------------------------------------------------------
o: Object [mrb_value]
C: class/module [mrb_value]
S: String [mrb_value]
A: Array [mrb_value]
H: Hash [mrb_value]
......@@ -434,6 +435,29 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
}
}
break;
case 'C':
{
mrb_value *p;
p = va_arg(ap, mrb_value*);
if (i < argc) {
mrb_value ss;
ss = *sp++;
switch (mrb_type(ss)) {
case MRB_TT_CLASS:
case MRB_TT_MODULE:
case MRB_TT_SCLASS:
break;
default:
mrb_raisef(mrb, E_TYPE_ERROR, "%S is not class/module", ss);
break;
}
*p = ss;
i++;
}
}
break;
case 'S':
{
mrb_value *p;
......@@ -732,7 +756,7 @@ mrb_mod_append_features(mrb_state *mrb, mrb_value mod)
mrb_value klass;
mrb_check_type(mrb, mod, MRB_TT_MODULE);
mrb_get_args(mrb, "o", &klass);
mrb_get_args(mrb, "C", &klass);
mrb_include_module(mrb, mrb_class_ptr(klass), mrb_class_ptr(mod));
return mod;
}
......@@ -780,7 +804,7 @@ mrb_mod_include_p(mrb_state *mrb, mrb_value mod)
mrb_value mod2;
struct RClass *c = mrb_class_ptr(mod);
mrb_get_args(mrb, "o", &mod2);
mrb_get_args(mrb, "C", &mod2);
mrb_check_type(mrb, mod2, MRB_TT_MODULE);
while (c) {
......@@ -1059,7 +1083,7 @@ mrb_class_new_class(mrb_state *mrb, mrb_value cv)
mrb_value super;
struct RClass *new_class;
if (mrb_get_args(mrb, "|o", &super) == 0) {
if (mrb_get_args(mrb, "|C", &super) == 0) {
super = mrb_obj_value(mrb->object_class);
}
new_class = mrb_class_new(mrb, mrb_class_ptr(super));
......
......@@ -542,7 +542,7 @@ obj_is_instance_of(mrb_state *mrb, mrb_value self)
mrb_value arg;
mrb_bool instance_of_p;
mrb_get_args(mrb, "o", &arg);
mrb_get_args(mrb, "C", &arg);
instance_of_p = mrb_obj_is_instance_of(mrb, self, mrb_class_ptr(arg));
return mrb_bool_value(instance_of_p);
......@@ -715,7 +715,7 @@ mrb_obj_is_kind_of_m(mrb_state *mrb, mrb_value self)
mrb_value arg;
mrb_bool kind_of_p;
mrb_get_args(mrb, "o", &arg);
mrb_get_args(mrb, "C", &arg);
kind_of_p = mrb_obj_is_kind_of(mrb, self, mrb_class_ptr(arg));
return mrb_bool_value(kind_of_p);
......
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