Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created September 5, 2011 03:37
Show Gist options
  • Save TooTallNate/1194032 to your computer and use it in GitHub Desktop.
Save TooTallNate/1194032 to your computer and use it in GitHub Desktop.
Creating a Cocoa GUI window with NodObjC
var $ = require('./')
$.import('Foundation')
$.import('Cocoa')
var pool = $.NSAutoreleasePool('alloc')('init')
var app = $.NSApplication('sharedApplication')
var style = $.NSClosableWindowMask | $.NSResizableWindowMask
| $.NSTexturedBackgroundWindowMask | $.NSTitledWindowMask
| $.NSMiniaturizableWindowMask
var rect = $.NSMakeRect(50, 50, 600, 400)
var win = $.NSWindow('alloc')('initWithContentRect', rect
, 'styleMask', style
, 'backing', $.NSBackingStoreBuffered
, 'defer', 0)
win('makeKeyAndOrderFront', win)
app('run')
pool('release')
@billymoon
Copy link

I get an error myself

File contents...

var $ = require('NodObjC')
$.import('Foundation')
$.import('Cocoa')

var pool = $.NSAutoreleasePool('alloc')('init')

var app = $.NSApplication('sharedApplication')
var style = $.NSClosableWindowMask | $.NSResizableWindowMask
| $.NSTexturedBackgroundWindowMask | $.NSTitledWindowMask
| $.NSMiniaturizableWindowMask

var rect = $.NSMakeRect(50, 50, 600, 400)
var win = $.NSWindow('alloc')('initWithContentRect', rect
, 'styleMask', style
, 'backing', $.NSBackingStoreBuffered
, 'defer', 0)
win('makeKeyAndOrderFront', win)
app('run')

pool('release')

output from command: node cocoa-gui

Segmentation fault
bash-3.2$

I would love to get this cocoa working with node - but can't seem to get any of it to work. Any idea what a Segmentation fault is, what causes it?

@TooTallNate
Copy link
Author

@billymoon Which node version? I seem to have the most luck on v0.5.5. Also does even the hello world example in the README work?

@billymoon
Copy link

billymoon commented Sep 15, 2011 via email

@TooTallNate
Copy link
Author

Oh I see what's going on. You're on [email protected]. That version doesn't have a lot of the good stuff. I just published v0.0.7 which gives support back for node 0.4.x. So re-run npm install NodObjC and let me know how it goes.

@billymoon
Copy link

billymoon commented Sep 15, 2011 via email

@TooTallNate
Copy link
Author

@billymoon Come to IRC room #nodobjc on Freenode and I can help walk you through it.

@billymoon
Copy link

billymoon commented Sep 15, 2011 via email

@TooTallNate
Copy link
Author

TooTallNate commented Sep 15, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment