From ac22a63ae3c29ac3921f53ac63ae981ab0def744 Mon Sep 17 00:00:00 2001 From: dearblue Date: Fri, 31 Dec 2021 19:12:11 +0900 Subject: Call functions directly from `mrb_ensure_float_type()` ref. commit 7f40b645d2773c8f50c48ae4adf90488e164da55 Currently, the build configurations `MRB_USE_COMPLEX` and `MRB_USE_RATIONAL` are not listed in the documentation. In other words, they are hidden settings. They are defined in `mrbgems/mruby-{complex,rational}/mrbgem.rake`. So this patch assumes that it is safe to refer to these functions in core-gems directly from core functions. However, applications that link with `libmruby_core.a` will have compatibility issues. In fact, `mrbgems/mruby-bin-mrbc` links with `libmruby_core.a`, so I had to prepare a dummy function. --- src/object.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/object.c b/src/object.c index 8a2addc20..21376d08c 100644 --- a/src/object.c +++ b/src/object.c @@ -499,6 +499,9 @@ mrb_ensure_int_type(mrb_state *mrb, mrb_value val) } #ifndef MRB_NO_FLOAT +mrb_value mrb_complex_to_f(mrb_state *mrb, mrb_value comp); // provided by mruby-complex with MRB_USE_COMPLEX +mrb_value mrb_rational_to_f(mrb_state *mrb, mrb_value rat); // provided by mruby-rational with MRB_USE_RATIONAL + MRB_API mrb_value mrb_ensure_float_type(mrb_state *mrb, mrb_value val) { @@ -512,9 +515,15 @@ mrb_ensure_float_type(mrb_state *mrb, mrb_value val) case MRB_TT_FLOAT: return val; +#ifdef MRB_USE_RATIONAL case MRB_TT_RATIONAL: + return mrb_rational_to_f(mrb, val); +#endif + +#ifdef MRB_USE_COMPLEX case MRB_TT_COMPLEX: - return mrb_type_convert(mrb, val, MRB_TT_FLOAT, MRB_SYM(to_f)); + return mrb_complex_to_f(mrb, val); +#endif default: mrb_raisef(mrb, E_TYPE_ERROR, "%Y cannot be converted to Float", val); -- cgit v1.2.3