MRI: {Rect,Color,Tone}#initialize_copy instead of #clone #3
|
@ -195,17 +195,6 @@ rb_bool_new(bool value)
|
|||
return objectLoad<Typ>(argc, argv, self, Typ##Type); \
|
||||
}
|
||||
|
||||
#define CLONE_FUNC(Klass) \
|
||||
static mrb_value \
|
||||
Klass##Clone(mrb_state *mrb, mrb_value self) \
|
||||
{ \
|
||||
Klass *k = getPrivateData<Klass>(mrb, self); \
|
||||
mrb_value dupObj = mrb_obj_clone(mrb, self); \
|
||||
Klass *dupK = new Klass(*k); \
|
||||
setPrivateData(mrb, dupObj, dupK, Klass##Type); \
|
||||
return dupObj; \
|
||||
}
|
||||
|
||||
#define CLONE_FUN(Klass) \
|
||||
RB_METHOD(Klass##Clone) \
|
||||
{ \
|
||||
|
@ -217,6 +206,18 @@ rb_bool_new(bool value)
|
|||
return dupObj; \
|
||||
}
|
||||
|
||||
#define INITCOPY_FUN(Klass) \
|
||||
RB_METHOD(Klass##InitCopy) \
|
||||
{ \
|
||||
VALUE original; \
|
||||
rb_get_args(argc, argv, "o", &original); \
|
||||
if (!OBJ_INIT_COPY(self, original)) \
|
||||
return self; \
|
||||
Klass *k = getPrivateData<Klass>(original); \
|
||||
setPrivateData(self, new Klass(*k), Klass##Type); \
|
||||
return self; \
|
||||
}
|
||||
|
||||
/* If we're not binding a disposable class,
|
||||
* we want to #undef DEF_PROP_CHK_DISP */
|
||||
#define DEF_PROP_CHK_DISP \
|
||||
|
|
|
@ -148,9 +148,9 @@ MARSH_LOAD_FUN(Color)
|
|||
MARSH_LOAD_FUN(Tone)
|
||||
MARSH_LOAD_FUN(Rect)
|
||||
|
||||
CLONE_FUN(Tone)
|
||||
CLONE_FUN(Color)
|
||||
CLONE_FUN(Rect)
|
||||
INITCOPY_FUN(Tone)
|
||||
INITCOPY_FUN(Color)
|
||||
INITCOPY_FUN(Rect)
|
||||
|
||||
#define INIT_BIND(Klass) \
|
||||
{ \
|
||||
|
@ -159,8 +159,8 @@ CLONE_FUN(Rect)
|
|||
rb_define_class_method(klass, "_load", Klass##Load); \
|
||||
serializableBindingInit<Klass>(klass); \
|
||||
_rb_define_method(klass, "initialize", Klass##Initialize); \
|
||||
_rb_define_method(klass, "initialize_copy", Klass##InitCopy); \
|
||||
_rb_define_method(klass, "set", Klass##Set); \
|
||||
_rb_define_method(klass, "clone", Klass##Clone); \
|
||||
_rb_define_method(klass, "==", Klass##Equal); \
|
||||
_rb_define_method(klass, "to_s", Klass##Stringify); \
|
||||
_rb_define_method(klass, "inspect", Klass##Stringify); \
|
||||
|
|
Loading…
Reference in New Issue