Skip to content

Commit

Permalink
Convert nil int/float arguments to 0
Browse files Browse the repository at this point in the history
Some games pass nil as bgs/bgm play pos arg :/
  • Loading branch information
Cloudef committed Mar 25, 2020
1 parent 9dc4291 commit 226b59c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions binding-mri/binding-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,12 @@ rb_float_arg(VALUE arg, double *out, int argPos = 0)
*out = FIX2INT(arg);
break;

case RUBY_T_NIL :
*out = 0;
break;

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));
}
}

Expand All @@ -246,8 +250,12 @@ rb_int_arg(VALUE arg, int *out, int argPos = 0)
*out = FIX2INT(arg);
break;

case RUBY_T_NIL :
*out = 0;
break;

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));
}
}

Expand Down

0 comments on commit 226b59c

Please sign in to comment.