summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-complex/src/complex.c
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-complex/src/complex.c')
-rw-r--r--mrbgems/mruby-complex/src/complex.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c
index 5305e09d8..e4143a762 100644
--- a/mrbgems/mruby-complex/src/complex.c
+++ b/mrbgems/mruby-complex/src/complex.c
@@ -67,8 +67,17 @@ complex_ptr(mrb_state *mrb, mrb_value v)
}
#endif
-static mrb_value
-complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
+void
+mrb_complex_get(mrb_state *mrb, mrb_value cpx, mrb_float *r, mrb_float *i)
+{
+ struct mrb_complex *c = complex_ptr(mrb, cpx);
+
+ *r = c->real;
+ *i = c->imaginary;
+}
+
+mrb_value
+mrb_complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
{
struct RClass *c = mrb_class_get_id(mrb, MRB_SYM(Complex));
struct mrb_complex *p;
@@ -80,6 +89,8 @@ complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
return mrb_obj_value(comp);
}
+#define complex_new(mrb, real, imag) mrb_complex_new(mrb, real, imag)
+
static mrb_value
complex_real(mrb_state *mrb, mrb_value self)
{
@@ -225,7 +236,7 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
#ifdef COMPLEX_USE_ISTRUCT
mrb_assert(sizeof(struct mrb_complex) < ISTRUCT_DATA_SIZE);
#endif
- comp = mrb_define_class(mrb, "Complex", mrb_class_get_id(mrb, MRB_SYM(Numeric)));
+ comp = mrb_define_class_id(mrb, MRB_SYM(Complex), mrb_class_get_id(mrb, MRB_SYM(Numeric)));
#ifdef COMPLEX_USE_ISTRUCT
MRB_SET_INSTANCE_TT(comp, MRB_TT_ISTRUCT);
#else