BT

Embedding MacRuby For Application Scripting

by Werner Schuster on Oct 14, 2008 |

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,...)?

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

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT