complex.c (mrb_complex_copy): allow copying of complex numbers.
MODIFY
include/mruby/internal.h
include/mruby/internal.h
@@ -88,6 +88,7 @@ mrb_value mrb_complex_add(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_complex_sub(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_complex_mul(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_complex_div(mrb_state *mrb, mrb_value x, mrb_value y);
+void mrb_complex_copy(mrb_state *mrb, mrb_value x, mrb_value y);
#endif
#ifdef MRB_USE_RATIONAL
mrb_value mrb_rational_new(mrb_state *mrb, mrb_int x, mrb_int y);

MODIFY
mrbgems/mruby-bin-mrbc/tools/mrbc/stub.c
mrbgems/mruby-bin-mrbc/tools/mrbc/stub.c
@@ -34,6 +34,9 @@ mrb_value mrb_complex_to_f(mrb_state *mrb, mrb_value x)
{
return mrb_nil_value();
}
+void mrb_complex_copy(mrb_state *mrb, mrb_value x, mrb_value y)
+{
+}
#endif
#ifdef MRB_USE_RATIONAL

MODIFY
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
@@ -84,6 +84,15 @@ mrb_complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
#define complex_new(mrb, real, imag) mrb_complex_new(mrb, real, imag)
+void
+mrb_complex_copy(mrb_state *mrb, mrb_value x, mrb_value y)
+{
+ struct mrb_complex *p1 = complex_ptr(mrb, x);
+ struct mrb_complex *p2 = complex_ptr(mrb, y);
+ p1->real = p2->real;
+ p1->imaginary = p2->imaginary;
+}
+
static mrb_value
complex_real(mrb_state *mrb, mrb_value self)
{

MODIFY
src/class.c
src/class.c
@@ -2747,6 +2747,11 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
mrb_rational_copy(mrb, dest, obj);
break;
#endif
+#ifdef MRB_USE_COMPLEX
+ case MRB_TT_COMPLEX:
+ mrb_complex_copy(mrb, dest, obj);
+ break;
+#endif
default:
break;

complex.c (mrb_complex_copy): allow copying of complex numbers.