Hi, I'm playing with the new block syntax of objc recently. I tried to call a ruby block from an objc block-ish methods but failed. The code snippet: @implementation BlockTest ... -(void)testBlock:(void^(int i))block { block(self.x); } ... @end; MacRuby codes: b.testBlock do |x| puts x end Anything wrong with my codes? or it's not supported yet? (if so, any plan to do it?) Best wishes Linan
Hi Linan, This is currently not implemented. It is not planned for the upcoming release mostly because I don't think it's that important, since all block methods in Cocoa also have methods dealing with function pointers, which will be supported. If you have any need for such a feature we can tentatively implement it for the release. Laurent On Sep 15, 2009, at 4:28 PM, Linan Wang wrote:
Hi, I'm playing with the new block syntax of objc recently. I tried to call a ruby block from an objc block-ish methods but failed. The code snippet:
@implementation BlockTest ... -(void)testBlock:(void^(int i))block { block(self.x); } ... @end;
MacRuby codes:
b.testBlock do |x| puts x end
Anything wrong with my codes? or it's not supported yet? (if so, any plan to do it?)
Best wishes Linan _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hi Laurent, Thanks for the reply. I'm just playing with new functions, not on a project. It is not a highly demanded feature. I really appreciate your kind gesture. I wonder if there is any quick work around, e.g. put some macruby related codes into the objc codes so that ruby blocks can be invoked? Best wishes, Linan On 16 Sep 2009, at 01:26, Laurent Sansonetti wrote:
Hi Linan,
This is currently not implemented. It is not planned for the upcoming release mostly because I don't think it's that important, since all block methods in Cocoa also have methods dealing with function pointers, which will be supported.
If you have any need for such a feature we can tentatively implement it for the release.
Laurent
On Sep 15, 2009, at 4:28 PM, Linan Wang wrote:
Hi, I'm playing with the new block syntax of objc recently. I tried to call a ruby block from an objc block-ish methods but failed. The code snippet:
@implementation BlockTest ... -(void)testBlock:(void^(int i))block { block(self.x); } ... @end;
MacRuby codes:
b.testBlock do |x| puts x end
Anything wrong with my codes? or it's not supported yet? (if so, any plan to do it?)
Best wishes Linan _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Technically, a Ruby block is an Objective-C object of the Proc class, so you can simply pass the block to an Objective-C method that receives an "id" argument, then from that method you can send the - call: message on it, preferably using -performRubySelector: (look at the MacRuby.h header file or the EmbeddedMacRuby sample code for more information). It should then work :) Let me know if you have problems. HTH, Laurent On Sep 15, 2009, at 5:58 PM, Linan Wang wrote:
Hi Laurent, Thanks for the reply. I'm just playing with new functions, not on a project. It is not a highly demanded feature. I really appreciate your kind gesture. I wonder if there is any quick work around, e.g. put some macruby related codes into the objc codes so that ruby blocks can be invoked? Best wishes, Linan
On 16 Sep 2009, at 01:26, Laurent Sansonetti wrote:
Hi Linan,
This is currently not implemented. It is not planned for the upcoming release mostly because I don't think it's that important, since all block methods in Cocoa also have methods dealing with function pointers, which will be supported.
If you have any need for such a feature we can tentatively implement it for the release.
Laurent
On Sep 15, 2009, at 4:28 PM, Linan Wang wrote:
Hi, I'm playing with the new block syntax of objc recently. I tried to call a ruby block from an objc block-ish methods but failed. The code snippet:
@implementation BlockTest ... -(void)testBlock:(void^(int i))block { block(self.x); } ... @end;
MacRuby codes:
b.testBlock do |x| puts x end
Anything wrong with my codes? or it's not supported yet? (if so, any plan to do it?)
Best wishes Linan _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
This is currently not implemented. It is not planned for the upcoming release mostly because I don't think it's that important, since all block methods in Cocoa also have methods dealing with function pointers, which will be supported.
Not true of some of the new Foundation and AppKit APIs. This should be doable since we know what the low-level implementation for blocks is and we can build a the right trampoline. Of course, given my circumstances (not enough time for anything), “me” means “you.” -Ben
On Sep 16, 2009, at 6:49 PM, Benjamin Stiglitz wrote:
This is currently not implemented. It is not planned for the upcoming release mostly because I don't think it's that important, since all block methods in Cocoa also have methods dealing with function pointers, which will be supported.
Not true of some of the new Foundation and AppKit APIs. This should be doable since we know what the low-level implementation for blocks is and we can build a the right trampoline.
Yeah, it's doable, but is it urgent? I don't think so.
Of course, given my circumstances (not enough time for anything), “me” means “you.”
I'm sure you can hack something in the bus, come on :-) Laurent
participants (3)
-
Benjamin Stiglitz
-
Laurent Sansonetti
-
Linan Wang