kimura wataru
kimur****@i*****
Fri Feb 24 00:15:13 JST 2006
Hi, Wed, Feb 22, 2006 8:35:57 PM, Jonathan Paisley wrote: >Hi, > >I'm just wondering if we can use a method_added hook to automatically >invoke ns_overrides as necessary for NSObject subclasses? This would >mean ns_overrides shouldn't be needed at all. > >What do you think? > It's a good idea. I wrote the following method in OSX::NSBehaviorAttachment and tested. It seems to work fine. "method_added" is already defined in OSX::NSKVCBehaviorAttachment. So, I commented out this method_added at testing. I think to solve this is not so difficult, though my idea is not yet clear. def method_added(sym) return unless self.is_a? Class # ignore singleton methods sel = sym.to_s.gsub('_', ':') sel << ':' if instance_method(sym).arity > 0 and /[^:]\z/ =~ sel return unless self.objc_instance_method_type sel module_eval %Q! ns_override "#{sel}" !, __FILE__, __LINE__ end I found a bug of overriding at testing. Steps to Reproduce (1) override with ns_override a method twice(or more) (2) invoke super_method => NSInvalidArgumentException - *** -[NSProxy forwardInvocation:] called! patch to fix Index: framework/src/objc/OverrideMixin.m =================================================================== RCS file: /cvsroot/rubycocoa/src/framework/src/objc/OverrideMixin.m,v retrieving revision 1.12 diff -u -r1.12 OverrideMixin.m --- framework/src/objc/OverrideMixin.m 9 Feb 2006 11:49:46 -0000 1.12 +++ framework/src/objc/OverrideMixin.m 23 Feb 2006 15:13:38 -0000 @@ -308,9 +308,12 @@ } else { // override method + IMP imp = get_handler_ruby_method(me->method_types); + if (me->method_imp == imp) + return nil; mlp->method_list[0].method_name = me->method_name; mlp->method_list[0].method_types = strdup(me->method_types); - mlp->method_list[0].method_imp = get_handler_ruby_method(me->method_types); + mlp->method_list[0].method_imp = imp; mlp->method_count += 1; // super method -- kimura wataru