[MacRuby-devel] How to create loadable MacRuby bundle
Antonin Hildebrand
antonin at hildebrand.cz
Mon Oct 13 23:08:38 PDT 2008
Hi Laurent,
I'm porting my app from RubyCocoa to MacRuby. I wanted to implement
simple plugin system for this app..
Plugins contain not only ruby scripts, but also nib files (and maybe
other resource stuff).
I'm quite new to Mac development, so I may be totally wrong. My
approach was to create every plugin as a RubyCocoa loadable bundle.
In RubyCocoa during application startup I load all plugins using
NSBundle.bundleWithPath(path).load and it correctly does two things:
1. initializes nib machinery
2. calls my ruby script, in which I hook into main application (it
gives me the same ruby environment as has main application)
In ideal case I don't want limit plugin developers to use MacRuby,
RubyCocoa or any other particular technology.
I want them just to create loadable bundle and use my application
hooks in their init call (hooks should be accessible from their
environment somehow).
I can imagine to write ruby C-extension inside my main application to
bridge ruby methods into C and present hooks to plugins as plain C API
(which everybody should understand).
If this is too complicated, I can live with just MacRuby bundle support.
Antonin
On Tue, Oct 14, 2008 at 7:42 AM, Laurent Sansonetti
<lsansonetti at apple.com> wrote:
> Hi Antonin,
>
> On Oct 13, 2008, at 6:59 PM, Antonin Hildebrand wrote:
>
>> Hi,
>>
>> Is it possible to create loadable MacRuby bundle to be loaded into
>> another MacRuby application?
>>
>> I'm looking for replacement for RBBundleInit as described for
>> RubyCocoa here:
>> http://threeve.org/blog/2007/12/loadable-bundles-using-rubycocoa.html
>>
>> I'm loading bundles into my MacRuby app via:
>> NSBundle.bundleWithPath(path).load
>
>
> trunk has a preliminary Objective-C API that allows pure Objective-C
> apps to initialize and use MacRuby (look at the MacRuby class defined
> in the objc.h file in trunk), and RBBundleInit could therefore be
> implemented based on that.
>
> Could you give more details about what you are trying to do exactly?
> Loading a MacRuby bundle in a MacRuby app looks weird, you could just
> require the Ruby scripts.
>
> If you want to load a .bundle that contains native code in a MacRuby
> app, you can use the NSBundle API. You could also generate a dynamic
> library and "require" it (assuming you have an Init_xxx exported
> function).
>
> If you want to load a .bundle that contains MacRuby code in a non-
> MacRuby application, you will need the new Objective-C API (or use the
> standard C API) to prepare the bundle. I could work on a sample code
> that illustrates this if needed. The bundle could theoretically be
> loaded in MacRuby apps as well, thought it would be a little bit
> overkill since you could just directly "require" the Ruby scripts.
>
> Laurent
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
More information about the MacRuby-devel
mailing list