made mrb_get_args() better (optinal args, type checks); close #173 #176

This commit is contained in:
Yukihiro Matsumoto
2012-05-24 01:09:36 +09:00
parent 4f012f578f
commit ad9e841c53
17 changed files with 248 additions and 161 deletions
+2 -9
View File
@@ -177,10 +177,7 @@ mrb_ary_concat_m(mrb_state *mrb, mrb_value self)
{
mrb_value other;
mrb_get_args(mrb, "o", &other);
if (mrb_type(other) != MRB_TT_ARRAY) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "expected Array");
}
mrb_get_args(mrb, "A", &other);
mrb_ary_concat(mrb, self, other);
return self;
}
@@ -193,11 +190,7 @@ mrb_ary_plus(mrb_state *mrb, mrb_value self)
mrb_value other;
mrb_value ary;
mrb_get_args(mrb, "o", &other);
if (mrb_type(other) != MRB_TT_ARRAY) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "expected Array");
}
mrb_get_args(mrb, "A", &other);
ary = mrb_ary_new_capa(mrb, a1->len + RARRAY_LEN(other));
a2 = mrb_ary_ptr(ary);
memcpy(a2->buf, a1->buf, sizeof(mrb_value)*a1->len);