BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Embedding MacRuby For Application Scripting

| by Werner Schuster on Oct 14, 2008. Estimated reading time: 1 minute |

The upcoming MacRuby release will contain new features to facilitate embedding and using the runtime to script Objective-C applications. Matt Mower explains the reasons for choosing MacRuby over other Objective-C scripting options, as well as a few APIs currently available in the MacRuby trunk. The application Matt uses MacRuby for is Elysium, an application for generative music.

Something I've had in mind, almost from the beginning, was that Elysium should be scriptable. That, through the ability to script parts of the application, you can have more control over the musical strategy. For example a script might regulate how often new playheads are generated in order to control the "energy" of a piece.


Matt continues to explains how to use MacRuby from an Objective-C application and shows a few of the calls to use. For instance, to e xecute some Ruby source from a Cocoa application:

[[MacRuby sharedRuntime] evaluateString:rubySource]

Matt's examples also show an easy to way use snippets of Ruby code as callbacks for the Objective-C application.

To see the changes, which should make it into MacRuby 0.4, there's now a GitHub mirror of MacRuby (the Commits page for the repository).

MacRuby is tightly integrated with Objective-C, eg. many basic Ruby types are mapped directly to Objective-C types. With this, MacRuby has similar benefits as JRuby and IronRuby, ie. simple and efficient access to a large amount of existing libraries, such as the ones exposed by OS X. Apple, for instance, already uses Ruby (not MacRuby, though) as implementation language for the iPhone Enterprise utility.

Are you working on an Objective-C application? If yes, would you choose MacRuby or any of the other scripting options Matt Mower lists (Nu, JSCore,...)?

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and dont miss out on content that matters to you

BT