diff options
| author | dearblue <[email protected]> | 2021-12-31 19:12:11 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2021-12-31 19:12:11 +0900 |
| commit | ac22a63ae3c29ac3921f53ac63ae981ab0def744 (patch) | |
| tree | 7dd90c5218796c16977c7dfbaa3fb8e8f05905fb /src | |
| parent | 5ca17c2dce47c637728ed03661465d0ada0a61a9 (diff) | |
| download | mruby-ac22a63ae3c29ac3921f53ac63ae981ab0def744.tar.gz mruby-ac22a63ae3c29ac3921f53ac63ae981ab0def744.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/object.c | 11 |
1 files changed, 10 insertions, 1 deletions
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); |
