[MacRuby-devel] MacRuby class inside obj-c

Thibault Martin-Lagardette thibault.ml at gmail.com
Wed May 19 11:22:59 PDT 2010


That is correct. Support for blocks in MacRuby is not implemented (yet). :-)

-- 
Thibault Martin-Lagardette



On May 19, 2010, at 05:37, Louis-Philippe wrote:

> And by trying a bit I see blocks are not supported,
> am I right?
> 
> 2010/5/18 Laurent Sansonetti <lsansonetti at apple.com>
> Indeed, methods with normal arities (0..n arguments) conform to the Objective-C ABI, so using the bracket syntax just works. But for Ruby methods using complex arities (like splat or optional arguments), you will likely get a crash. This is why the -performRubySelector: method was introduced. It is better to always use that method, because it always works (in theory).
> 
> Laurent
> 
> 
> On May 18, 2010, at 3:05 PM, Louis-Philippe wrote:
> 
>> great!
>> I can even seem to send messages directly to my MacRuby classes and instances...
>> like:
>> id obj = [Foo new:@"objc"];
>> and
>> [obj hello];
>> 
>> but in the second case I get a compiler warning: "No -hello method found"??
>> 
>> 2010/5/18 Laurent Sansonetti <lsansonetti at apple.com>
>> Hi Louis-Philippe,
>> 
>> Assuming MacRuby code defines:
>> 
>> class Foo
>>  def initialize(message)
>>    @message
>>  end
>>  def hello
>>    puts "hello #{message}"
>>  end
>> end
>> 
>> You should be able to retrieve a reference to Foo using:
>> 
>> Class Foo = [[MacRuby sharedRuntime] evaluateString:@"Foo"];
>> 
>> Or, more simply:
>> 
>> Class foo = NSClassFromString(@"Foo");
>> 
>> You might want to use the first way in case the class has a complex path (if it's defined inside modules, like "Foo::Bar").
>> 
>> Later, you can send messages to it.
>> 
>> id obj = [Foo performRubySelector:@selector(new:) withArguments: @"objc", nil];
>> [obj performRubySelector:@selector(hello)];
>> 
>> Laurent
>> 
>> On May 18, 2010, at 2:31 PM, Louis-Philippe wrote:
>> 
>> > Hi,
>> > I don't know if this is the good list to ask this question as it is my first...
>> > So,
>> >
>> > I saw how I can have a MacRuby cocoa app, importing objective-c classes.
>> > I can't find info on how to do the opposite...  having an Objective-C cocoa app, importing and using MacRuby Classes...
>> >
>> > All I managed to do is to "evaluateFileAtPath:" and "evaluateString:"
>> >
>> > Thanks!
>> >
>> > L-P
>> > _______________________________________________
>> > MacRuby-devel mailing list
>> > MacRuby-devel at lists.macosforge.org
>> > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>> 
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>> 
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100519/636bc8f6/attachment.html>


More information about the MacRuby-devel mailing list