[MacRuby-devel] Using compiled MacRuby objects from an Objective-C application

Justin Schumacher justin at sweetspotdiabetes.com
Thu Dec 23 14:27:06 PST 2010


Laurent,

I made the switch to rbo files.  The load time was 3.6 seconds with .rb
files and 0.9 seconds with .rbo files.  That's a good improvement and is
acceptable for my project for the time being.  I did notice that the
Objective-C API method 'evaluateFileAtPath' cannot accept rbo files.  To
load the rbo files from Objective-C, I'm using the following pattern:

[[MacRuby sharedRuntime] evaluateString:[NSString stringWithFormat:@"require
'%@'", filename]];

Probably no big performance hit there, but I'm wondering if it would make
sense for evaluateFileAtPath to be able to accept rbo files as well as rb
files.

Thanks for the tip.  Looking forward to the ability to link macrubyc files
in with objective-c files...

-Justin

On Tue, Dec 21, 2010 at 1:02 PM, Laurent Sansonetti
<lsansonetti at apple.com>wrote:

> Hi Justin,
>
> Linking MacRuby object files into a pure Objective-C program is still
> tricky to do, and it has not been tested very well. I will look at writing
> some use case tests for macrubyc and see if we can get everything in good
> shape for the next release.
>
> I recommend to stick to .rbo compilation at this point. You just need to
> compile every .rb file of your app into an .rbo one, and leave the
> Objective-C code untouched. The startup time of .rbo files vs directly
> linking the object files should be negligible (unless you have tons of .rb
> files).
>
> You mention 3 seconds, that seems a lot. Maybe some work could also be done
> in macruby core to speed up loading your files. Could you tell me the
> startup time you get after compiling to .rbo? If it's still significant, we
> may need to investigate more.
>
> Laurent
>
> On Dec 20, 2010, at 5:18 PM, Justin Schumacher wrote:
>
> I'm working on an application that is primarily Objective-C but uses
> MacRuby as a plugin language (the application also has a C# / IronRuby
> counterpart on Windows, allowing for the plugins to be cross-platform).
>  I've been loading the ruby files at runtime using the Objective-C MacRuby
> API's sharedRuntime and bundling MacRuby into the application bundle.
>  However, the ruby plugins have gotten complex enough that parsing them is
> taking about 3 seconds at application startup on a modern MacBook Pro.  I
> would like reduce the load time by precompiling the ruby files and linking
> the resulting object files to the application.  So far I've done exactly
> that, but I can't figure out how to access the ruby classes at runtime from
> the Objective-C application.
>
> I've tried two techniques:
>
> // causes SIGABRT
> id rubyClass = [[MacRuby sharedRuntime] evaluateString:@"MyRubyClass"];
>
> - and -
>
> // returns NULL
> Class rubyClass = NSClassFromString(@"MyRubyClass");
>
> I would love to see an example or description of how this can be done---
> how to link pre-compiled ruby files (dylib) to an Objective-C application
> and then access the classes defined in those ruby files from the Objective-C
> environment..
>
> I've dug through the last 6 months of the archives, and I've found only one
> other reference to this question, but it was left mostly unanswered:
>
>
> http://lists.macosforge.org/pipermail/macruby-devel/2010-October/006206.html
>
> -Justin
> _______________________________________________
> 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/20101223/9235596b/attachment.html>


More information about the MacRuby-devel mailing list