Convert nil int/float arguments to 0

Some games pass nil as bgs/bgm play pos arg :/
This commit is contained in:
Jari Vetoniemi 2020-03-15 14:39:31 +09:00
parent 9dc42914de
commit 226b59c58e
1 changed files with 10 additions and 2 deletions

View File

@ -227,8 +227,12 @@ rb_float_arg(VALUE arg, double *out, int argPos = 0)
*out = FIX2INT(arg); *out = FIX2INT(arg);
break; break;
case RUBY_T_NIL :
*out = 0;
break;
default: default:
rb_raise(rb_eTypeError, "Argument %d: Expected float", argPos); rb_raise(rb_eTypeError, "Argument %d: Expected float (got 0x%x)", argPos, rb_type(arg));
} }
} }
@ -246,8 +250,12 @@ rb_int_arg(VALUE arg, int *out, int argPos = 0)
*out = FIX2INT(arg); *out = FIX2INT(arg);
break; break;
case RUBY_T_NIL :
*out = 0;
break;
default: default:
rb_raise(rb_eTypeError, "Argument %d: Expected fixnum", argPos); rb_raise(rb_eTypeError, "Argument %d: Expected fixnum (got 0x%x)", argPos, rb_type(arg));
} }
} }