[MacRuby] #999: Handle Obj-C protocols better in MacRuby
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ----------------------------------------+----------------------------------- MacRuby should be able to handle Protocols better. As of r4916, protocols can not really be used, because the `Protocol` class crashes. We should probably find a way so that Objects can define what protocols they conforms to. -- Ticket URL: <http://www.macruby.org/trac/ticket/999> MacRuby <http://macruby.org/>
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ----------------------------------------+----------------------------------- Comment(by martinlagardette@…): Attached is a patch that will: - Remove the NSInvocation warnings when using `Protocol#protocolWithName` - Make this work: `someObj.conformsToProtocol(Protocol.protocolWithName("NSCoding"))` -- Ticket URL: <http://www.macruby.org/trac/ticket/999#comment:1> MacRuby <http://macruby.org/>
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ----------------------------------------+----------------------------------- Comment(by lsansonetti@…): Please commit :) -- Ticket URL: <http://www.macruby.org/trac/ticket/999#comment:2> MacRuby <http://macruby.org/>
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ----------------------------------------+----------------------------------- Comment(by lsansonetti@…): I think this patch will not allow ruby classes to declare protocols they conform to, yet. I guess we would need to introduce an API for this. -- Ticket URL: <http://www.macruby.org/trac/ticket/999#comment:3> MacRuby <http://macruby.org/>
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ----------------------------------------+----------------------------------- Comment(by lsansonetti@…): Looks like the class_addProtocol() runtime function could be used. I wonder if we can call it automatically, once all methods of a known protocol are defined. -- Ticket URL: <http://www.macruby.org/trac/ticket/999#comment:4> MacRuby <http://macruby.org/>
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ----------------------------------------+----------------------------------- Comment(by martinlagardette@…): Replying to [comment:3 lsansonetti@…]:
I think this patch will not allow ruby classes to declare protocols they conform to, yet. I guess we would need to introduce an API for this. Yep, it won't. It will just "crash less" when using with +protocolWithName :-)
Replying to [comment:4 lsansonetti@…]:
Looks like the class_addProtocol() runtime function could be used. I wonder if we can call it automatically, once all methods of a known protocol are defined. Well, that's what I thought too. I wanted to see if I could fix this bug by using the runtime, but the main problem I stumbled upon is that I don't know where we could list the protocols a class conforms to?
-- Ticket URL: <http://www.macruby.org/trac/ticket/999#comment:5> MacRuby <http://macruby.org/>
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ----------------------------------------+----------------------------------- Comment(by martijn@…): Replying to [comment:4 lsansonetti@…]:
Looks like the class_addProtocol() runtime function could be used. I wonder if we can call it automatically, once all methods of a known protocol are defined.
To me, it feels there might be too much 'magic' in automatically adding protocols a class conforms to. Plus, there are plenty of protocols with no required but only optional methods. Would all MacRuby classes then automatically conform to these protocols? I don't mind manually indicating what protocols a class supports, as this helps make explicit what its responsibilities are. So what about just adding a class macro that calls class_addProtocol() during class definition? {{{ #!ruby class SourceListController add_protocol :NSOutlineViewDelegate def outlineView(outlineView, child:index, ofItem:item) ... end ... end }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/999#comment:6> MacRuby <http://macruby.org/>
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: closed Priority: major | Milestone: Component: MacRuby | Resolution: fixed Keywords: 0.8 | ----------------------------------------+----------------------------------- Changes (by eloy.de.enige@…): * keywords: => 0.8 * status: new => closed * resolution: => fixed Comment: After some more discussion we decided to override conformsToProtocol: on RubyObject, the superclass of all pure Ruby classes. This implementation will check if the object/class implements the required protocol methods. This has been committed in r4930, please give it a try (or the next nightly). -- Ticket URL: <http://www.macruby.org/trac/ticket/999#comment:7> MacRuby <http://macruby.org/>
#999: Handle Obj-C protocols better in MacRuby ----------------------------------------+----------------------------------- Reporter: martinlagardette@… | Owner: lsansonetti@… Type: enhancement | Status: closed Priority: major | Milestone: MacRuby 0.8 Component: MacRuby | Resolution: fixed Keywords: | ----------------------------------------+----------------------------------- Changes (by eloy.de.enige@…): * keywords: 0.8 => * milestone: => MacRuby 0.8 -- Ticket URL: <http://www.macruby.org/trac/ticket/999#comment:8> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby