Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Fix for issue #5 and to fix SDL on the mac #6

merged 3 commits into from

3 participants



i have pushed a few small commits you may want to merge, one to fix this:


and another to make SDL run on the mac using the Quartz backend.


Richard Mazo... added some commits
@creationix creationix merged commit b89f9ac into creationix:master

Great work. I was wondering how to fix it for OSX


Dude, how did you figure this one out?? Nice!

with the power of grayskull, and to a lesser extent this doc page

i wonder if this works for ffi too... Those includes don't have any side effects other than declaring stuff right?

the objc headers just declare functions that are used by the objc runtime, to send messages to objects and handle properties and so on. you can see the gory details here:

Oh, how intimately familiar I am with those crazy awesome functions :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 27, 2012
  1. use the correct method signature for EIO_WaitEvent

    Richard Mazorodze committed
  2. point sdl.js to the correct build directory

    Richard Mazorodze committed
  3. call [NSApplication sharedApplication] before SDL_Init(), otherwise t…

    Richard Mazorodze committed
    …he app will crash when SDL_SetVideoMode() is called
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 8 deletions.
  1. +1 −1  sdl.js
  2. +13 −5 src/
  3. +2 −2 src/sdl.h
2  sdl.js 100644 → 100755
@@ -1,4 +1,4 @@
-var SDL = module.exports = require('./build/default/node-sdl.node');
+var SDL = module.exports = require('./build/Release/node-sdl.node');
// Easy event emitter based event loop. Started automatically when the first
// listener is added.
18 src/
@@ -1,11 +1,21 @@
-#include "sdl.h"
-using namespace v8;
+#ifdef __APPLE__
+#include <objc/objc.h>
+#include <objc/objc-runtime.h>
+#include "SDL.h"
+using namespace v8;
extern "C" void
init(Handle<Object> target)
+#ifdef __APPLE__
+ // on the mac it is necessary to create to call [NSApplication sharedApplication]
+ // before we can create a rendering window
+ objc_msgSend(objc_lookUpClass("NSApplication"), sel_getUid("sharedApplication"));
NODE_SET_METHOD(target, "init", sdl::Init);
NODE_SET_METHOD(target, "initSubSystem", sdl::InitSubSystem);
NODE_SET_METHOD(target, "quit", sdl::Quit);
@@ -107,7 +117,6 @@ init(Handle<Object> target)
GL->Set(String::New("ACCUM_BLUE_SIZE"), Number::New(SDL_GL_ACCUM_BLUE_SIZE));
@@ -246,10 +255,9 @@ Handle<Value> sdl::SetError(const Arguments& args) {
return Undefined();
-static int sdl::EIO_WaitEvent(eio_req *req) {
+static void sdl::EIO_WaitEvent(eio_req *req) {
sdl::closure_t *closure = (sdl::closure_t *) req->data;
closure->status = SDL_WaitEvent(NULL);
- return 0;
static int sdl::EIO_OnEvent(eio_req *req) {
4 src/sdl.h
@@ -82,8 +82,8 @@ namespace sdl {
Persistent<Function> fn;
int status;
} closure_t;
- static int EIO_WaitEvent(eio_req *req);
- static int EIO_OnEvent(eio_req *req);
+ static void EIO_WaitEvent(eio_req *req);
+ static int EIO_OnEvent(eio_req *req);
Something went wrong with that request. Please try again.