Upgrade to Pro — share decks privately, control downloads, hide ads and more …

NodObjC - JSConf.ar 2012

NodObjC - JSConf.ar 2012

The slides for my talk from JSConf.ar 2012. I introduce NodObjC and explain what my purposes for creating it were.


May 21, 2012

More Decks by tootallnate

Other Decks in Technology


  1. 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
  2. ABOUT ME • Lucky enough to be one of the

    engineers on the awesome Learnboost team
  3. OBJECTIVE-C • A “strict superset” of C • Object-oriented •

    Has a “message-sending” syntax influenced by SmallTalk WHAT IS IT?
  4. 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
  5. 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
  6. 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 <audio> and <video> tags
  7. STORY TIME! + iTunes (on OS X) offers 2 APIs

    for interacting with it: • AppleScript • Objective-C’s “ScriptingBridge” framework
  8. 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.
  9. 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...
  10. • 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
  11. 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
  12. • 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!!!!
  13. 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
  14. 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
  15. 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”
  16. 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()”
  17. 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