Embedding MacRuby For Application Scripting
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,...)?
Martin Thompson Jul 27, 2014