MRI-Binding: Deduplicate code

This commit is contained in:
Jonas Kulla 2013-12-20 10:22:01 +01:00
parent cb36a28b09
commit d7ceff91a2
1 changed files with 3 additions and 41 deletions

View File

@ -201,19 +201,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
double *f = va_arg(ap, double*); double *f = va_arg(ap, double*);
VALUE fVal = *arg++; VALUE fVal = *arg++;
switch (rb_type(fVal)) rb_float_arg(fVal, f, argI);
{
case RUBY_T_FLOAT :
*f = rb_float_value(fVal);
break;
case RUBY_T_FIXNUM :
*f = rb_fix2int(fVal);
break;
default:
rb_raise(rb_eTypeError, "Argument %d: Expected float", argI);
}
++argI; ++argI;
break; break;
@ -227,20 +215,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
int *i = va_arg(ap, int*); int *i = va_arg(ap, int*);
VALUE iVal = *arg++; VALUE iVal = *arg++;
switch (rb_type(iVal)) rb_int_arg(iVal, i, argI);
{
case RUBY_T_FLOAT :
// FIXME check int range?
*i = rb_num2long(iVal);
break;
case RUBY_T_FIXNUM :
*i = rb_fix2int(iVal);
break;
default:
rb_raise(rb_eTypeError, "Argument %d: Expected fixnum", argI);
}
++argI; ++argI;
break; break;
@ -254,20 +229,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
bool *b = va_arg(ap, bool*); bool *b = va_arg(ap, bool*);
VALUE bVal = *arg++; VALUE bVal = *arg++;
switch (rb_type(bVal)) rb_bool_arg(bVal, b, argI);
{
case RUBY_T_TRUE :
*b = true;
break;
case RUBY_T_FALSE :
case RUBY_T_NIL :
*b = false;
break;
default:
rb_raise(rb_eTypeError, "Argument %d: Expected bool", argI);
}
++argI; ++argI;
break; break;