diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-05-21 16:17:21 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-05-21 21:08:26 +0900 |
| commit | c02e63eb77b68377239287acccf371516177a8b9 (patch) | |
| tree | 3bce58e84f885d85ad0589b05a615442d41d9f3f /mrbgems/mruby-complex | |
| parent | fccec8964a1b30cef8ff9d97e0e01f3a348e318b (diff) | |
| download | mruby-c02e63eb77b68377239287acccf371516177a8b9.tar.gz mruby-c02e63eb77b68377239287acccf371516177a8b9.zip | |
Use `MRB_TT_ISTRUCT` for `Complex` numbers if possible.
Diffstat (limited to 'mrbgems/mruby-complex')
| -rw-r--r-- | mrbgems/mruby-complex/src/complex.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c index 5de0ae9a4..c6fb7a829 100644 --- a/mrbgems/mruby-complex/src/complex.c +++ b/mrbgems/mruby-complex/src/complex.c @@ -7,6 +7,29 @@ struct mrb_complex { mrb_float imaginary; }; +#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT) + +#define COMPLEX_USE_ISTRUCT +/* use TT_ISTRUCT */ +#include <mruby/istruct.h> + +#define complex_ptr(mrb, v) (struct mrb_complex*)mrb_istruct_ptr(v) + +static mrb_value +complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary) +{ + struct RClass *c = mrb_class_get(mrb, "Complex"); + struct RIStruct *s = (struct RIStruct*)mrb_obj_alloc(mrb, MRB_TT_ISTRUCT, c); + mrb_value comp = mrb_obj_value(s); + struct mrb_complex *p = complex_ptr(mrb, comp); + p->real = real; + p->imaginary = imaginary; + + return comp; +} + +#else +/* use TT_DATA */ #include <mruby/data.h> static const struct mrb_data_type mrb_complex_type = {"Complex", mrb_free}; @@ -35,6 +58,7 @@ complex_ptr(mrb_state *mrb, mrb_value v) } return p; } +#endif static mrb_value complex_real(mrb_state *mrb, mrb_value self) |
