The slides for my talk from JSConf.ar 2012. I introduce NodObjC and explain what my purposes for creating it were.
Bringing Objective-C to Node.js
By Nathan Rajlich
Hola JSConf Argentina!
• My name is Nathan Rajlich
• I have been playing with Node.js for a little over 2 years now
• Have written a slew of useful and not-so-useful modules for
Node that are available through npm
• One of the Node.js core committers
• Lucky enough to be one of the engineers on
the awesome Learnboost team
So who here has written an OS X or iOS app?
• A “strict superset” of C
• Has a “message-sending” syntax inﬂuenced by SmallTalk
WHAT IS IT?
WHAT IS IT?
C functions are (still)
are standard C
Method names and
• Originally gained traction through Steve Jobs’ former
• When NeXT got acquired by Apple in 1996, Objective-C was
adapted to create applications for Mac OS X
• Has gained more popularity in the last few years because of
iOS and the App Store
Objective-C == Apple
This is JSConf!
Why am I talking about Objective-C?
Let’s go back to August 2010...
• I was still new to Node.js
• I was still in the mode where I try to do everything with Node
• So naturally, I wanted to interact with iTunes using Node.js
• The ultimate goal being to write a web app that would stream
audio/video from an iTunes installation to a regular web
browser using the and tags
iTunes (on OS X) offers 2 APIs for interacting with it:
• Objective-C’s “ScriptingBridge” framework
The AppleScript command
we want to execute
The callback function to
invoke when the
AppleScript can return all kinds
Array, Object, Number, String,
Date, Buffer, etc.
• You have to manually construct Strings for the commands
• Internally uses a child process for every command
• Who wants to write English to create programs anyway?
But... it’s not so great after all...
WE CAN DO BETTER!
So I thought to myself...
• A native Node.js binding to the “iTunes.h” header ﬁle
• Should be a lot faster than using “node-applescript” to
communicate with iTunes
You create a
Every function is
expects a callback
The API attempts
to map to the
“iTunes.h” ﬁle as
best as possible
• Quickly got out-of-control in terms of ﬁles and LOC
• Every exposed API from “iTunes.h” needs accompanying
• Worse yet, it can only interact with one “iTunes object” at a
time (a list of objects requires separate thread pool calls)
Too much code!!!!
So then I thought to myself...
THERE’S GOT TO BE
Soon, I was introduced to MacRuby
I WANT THIS, BUT IN NODE
The NodeJS ⁵ Objective-C bridge
A few other “bridges” to Objective-C:
NodObjC is conceptually very similar to these
other bridges, except that it runs in Node.js
• Started developing it in July 2010
• Still a relatively young project, and not yet feature-
• Already at the point where you can create full-ﬂedged
NodObjC has 2 modes of operation:
Use “module-mode” when
creating a module that
depends on NodObjC
Use “global-mode” when
creating an application, or
some other “end product”
Importing a custom framework?
See: man gen_bridge_metadata
[ do Node REPL live demo... ]
• NodObjC is at an interesting stage of its development
• It is very usable, but there are some edge-case features that
may or may not be show-stoppers for some people
• C Blocks are only partially implemented
• Needs some better handling of BridgeSupport ﬁles
• Needs support for vararg functions, like “NSLog()”
• node-fﬁ, NodObjC’s core dependency, is currently ﬁnishing up
a big refactor for its v1.0 release.
• NodObjC will have to be refactored a little to use node-fﬁ 1.0
• NodObjC’s API will likely remain unchanged after the refactor
Thanks for listening!