object.c: introduce `mrb_ensure_{int,float}_type`.
Since `mrb_to_integer` and `mrb_to_float` does not convert the object
but checks types, they are named so by historical reason. We introduced
properly named functions.
This commit obsoletes the following functions:
* mrb_to_integer()
* mrb_to_int()
* mrb_to_float()
Use `mrb_ensure_int_type()` instead for the first 2 functions. Use
`mrb_ensure_float_type()` for the last.
MODIFY
include/mruby.h
include/mruby.h
@@ -1269,7 +1269,9 @@ MRB_API mrb_bool mrb_obj_eq(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
#ifndef MRB_NO_FLOAT
-MRB_API mrb_value mrb_to_float(mrb_state *mrb, mrb_value val);
+MRB_API mrb_value mrb_ensure_float_type(mrb_state *mrb, mrb_value val);
+/* obsolete: use mrb_ensure_float_type() instead */
+#define mrb_to_float(mrb, val) mrb_ensure_float_type(mrb, val)
#endif
MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj);
MRB_API mrb_bool mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
@@ -1398,9 +1400,11 @@ MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str);
#define mrb_to_str(mrb, str) mrb_ensure_string_type(mrb,str)
/* obsolete: use mrb_obj_as_string() instead */
#define mrb_str_to_str(mrb, str) mrb_obj_as_string(mrb, str)
-MRB_API mrb_value mrb_to_integer(mrb_state *mrb, mrb_value val);
-#define mrb_to_int(mrb, val) mrb_to_integer(mrb, val)
-#define mrb_as_int(mrb, val) mrb_integer(mrb_to_integer(mrb, val))
+MRB_API mrb_value mrb_ensure_int_type(mrb_state *mrb, mrb_value val);
+#define mrb_as_int(mrb, val) mrb_integer(mrb_ensure_int_type(mrb, val))
+/* obsolete: use mrb_ensure_int_type() instead */
+#define mrb_to_integer(mrb, val) mrb_ensure_int_type(mrb, val)
+#define mrb_to_int(mrb, val) mrb_ensure_int_type(mrb, val)
/* string type checking (contrary to the name, it doesn't convert) */
MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);

MODIFY
src/kernel.c
src/kernel.c
@@ -659,7 +659,7 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_method(mrb, krn, "respond_to?", obj_respond_to, MRB_ARGS_ARG(1,1)); /* 15.3.1.3.43 */
mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, MRB_ARGS_NONE()); /* 15.3.1.3.46 */
mrb_define_method(mrb, krn, "__case_eqq", mrb_obj_ceqq, MRB_ARGS_REQ(1)); /* internal */
- mrb_define_method(mrb, krn, "__to_int", mrb_to_integer, MRB_ARGS_NONE()); /* internal */
+ mrb_define_method(mrb, krn, "__to_int", mrb_ensure_int_type, MRB_ARGS_NONE()); /* internal */
mrb_define_method(mrb, krn, "__ENCODING__", mrb_encoding, MRB_ARGS_NONE());
mrb_include_module(mrb, mrb->object_class, mrb->kernel_module);

MODIFY
src/object.c
src/object.c
@@ -485,7 +485,7 @@ mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c)
}
MRB_API mrb_value
-mrb_to_integer(mrb_state *mrb, mrb_value val)
+mrb_ensure_int_type(mrb_state *mrb, mrb_value val)
{
if (!mrb_integer_p(val)) {
#ifndef MRB_NO_FLOAT
@@ -500,7 +500,7 @@ mrb_to_integer(mrb_state *mrb, mrb_value val)
#ifndef MRB_NO_FLOAT
MRB_API mrb_value
-mrb_to_float(mrb_state *mrb, mrb_value val)
+mrb_ensure_float_type(mrb_state *mrb, mrb_value val)
{
if (mrb_nil_p(val)) {
mrb_raise(mrb, E_TYPE_ERROR, "can't convert nil into Float");

object.c: introduce `mrb_ensure_{int,float}_type`.

Since `mrb_to_integer` and `mrb_to_float` does not convert the object
but checks types, they are named so by historical reason. We introduced
properly named functions.

This commit obsoletes the following functions:

* mrb_to_integer()
* mrb_to_int()
* mrb_to_float()

Use `mrb_ensure_int_type()` instead for the first 2 functions. Use
`mrb_ensure_float_type()` for the last.