Skip to content

Commit

Permalink
overwrite -[NSObject description] in every new subclass + optimized o…
Browse files Browse the repository at this point in the history
…ther overloaded methods

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@2132 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Aug 2, 2009
1 parent 808073f commit a3ff57f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions class.c
Expand Up @@ -75,16 +75,23 @@ rb_obj_imp_isEqual(void *rcv, SEL sel, void *obj)
return RFIXNUM(rcv)->value == RFIXNUM(obj)->value;
}

return rb_funcall((VALUE)rcv, idEq, 1, OC2RB(obj)) == Qtrue;
VALUE arg = OC2RB(obj);
return rb_vm_call((VALUE)rcv, selEq, 1, &arg, false) == Qtrue;
}

static void *
rb_obj_imp_init(void *rcv, SEL sel)
{
rb_funcall((VALUE)rcv, idInitialize, 0);
rb_vm_call((VALUE)rcv, selInitialize, 0, NULL, false);
return rcv;
}

static void *
rb_obj_imp_description(void *rcv, SEL sel)
{
return (void *)rb_vm_call((VALUE)rcv, selToS, 0, NULL, false);
}

static VALUE
rb_objc_init(VALUE rcv, SEL sel)
{
Expand Down Expand Up @@ -117,6 +124,7 @@ rb_define_object_special_methods(VALUE klass)
(IMP)rb_obj_imp_allocWithZone);
rb_objc_install_method((Class)klass, selIsEqual, (IMP)rb_obj_imp_isEqual);
rb_objc_install_method((Class)klass, selInit, (IMP)rb_obj_imp_init);
rb_objc_install_method((Class)klass, selDescription, (IMP)rb_obj_imp_description);
}

static VALUE
Expand Down
2 changes: 2 additions & 0 deletions id.c
Expand Up @@ -65,6 +65,8 @@ Init_id(void)
selInit = sel_registerName("init");
selInitialize = sel_registerName("initialize");
selInitialize2 = sel_registerName("initialize:");
selDescription = sel_registerName("description");
selInspect = sel_registerName("inspect");
selNew = sel_registerName("new");
selRespondTo = sel_registerName("respond_to?:");
selMethodMissing = sel_registerName("method_missing:");
Expand Down
2 changes: 2 additions & 0 deletions id.h
Expand Up @@ -75,6 +75,8 @@ extern SEL selAllocWithZone;
extern SEL selInit;
extern SEL selInitialize;
extern SEL selInitialize2;
extern SEL selDescription;
extern SEL selInspect;
extern SEL selNew;
extern SEL selRespondTo;
extern SEL selMethodMissing;
Expand Down

0 comments on commit a3ff57f

Please sign in to comment.