Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created September 5, 2011 03:37
Show Gist options
  • Select an option

  • Save TooTallNate/1194032 to your computer and use it in GitHub Desktop.

Select an option

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')
@TooTallNate

Copy link
Copy Markdown
Author

Results in:

@billymoon

Copy link
Copy Markdown

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
Copy Markdown
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

billymoon commented Sep 15, 2011 via email

Copy link
Copy Markdown

@TooTallNate

Copy link
Copy Markdown
Author

Oh I see what's going on. You're on NodObjC@0.0.3. 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

billymoon commented Sep 15, 2011 via email

Copy link
Copy Markdown

@TooTallNate

Copy link
Copy Markdown
Author

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

@billymoon

billymoon commented Sep 15, 2011 via email

Copy link
Copy Markdown

@TooTallNate

TooTallNate commented Sep 15, 2011 via email

Copy link
Copy Markdown
Author

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