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

Laurent Sansonetti lsansonetti at apple.com
Tue Dec 21 13:02:01 PST 2010


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

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


More information about the MacRuby-devel mailing list