ABOUT ME • My name is Nathan Rajlich • I have been loving JavaScript for about 5 years • 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
OBJECTIVE-C WHAT IS IT? bracket-syntax = sending messages C functions are (still) first-class citizens Objective-C “objects” are standard C pointers Method names and arguments are intertwined
OBJECTIVE-C • Originally gained traction through Steve Jobs’ former company: NeXT • 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 HISTORY
STORY TIME! 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
NODE-APPLESCRIPT The AppleScript command we want to execute The callback function to invoke when the command completes AppleScript can return all kinds of values: Array, Object, Number, String, Date, Buffer, etc.
NODE-APPLESCRIPT • 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? It Works! But... it’s not so great after all...
• A native Node.js binding to the “iTunes.h” header file • Has the opportunity to massage into a nice JavaScript API • Should be a lot faster than using “node-applescript” to communicate with iTunes ATTEMPT #2: NODE-ITUNES gh://TooTallNate/node-iTunes
NODE-ITUNES You create a connection to iTunes first Every function is asynchronous and expects a callback function The API attempts to map to the “iTunes.h” file as best as possible
• Quickly got out-of-control in terms of files and LOC • Every exposed API from “iTunes.h” needs accompanying bridge code to expose it to JavaScript • Worse yet, it can only interact with one “iTunes object” at a time (a list of objects requires separate thread pool calls) NODE-ITUNES Too much code!!!!
NODOBJC • MacRuby • JSCocoa • PyObjC A few other “bridges” to Objective-C: NodObjC is conceptually very similar to these other bridges, except that it runs in Node.js
NODOBJC • Started developing it in July 2010 • Still a relatively young project, and not yet feature- complete • Already at the point where you can create full-fledged iOS or OS X applications using nothing but JavaScript and Node.js
NODOBJC Module-mode Global-mode vs. 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”
FUTURE PLANS • 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 files • Needs support for vararg functions, like “NSLog()”
FUTURE PLANS • node-ffi, NodObjC’s core dependency, is currently finishing up a big refactor for its v1.0 release. • NodObjC will have to be refactored a little to use node-ffi 1.0 • NodObjC’s API will likely remain unchanged after the refactor