GithubHelp home page GithubHelp logo

tootallnate / nodobjc Goto Github PK

View Code? Open in Web Editor NEW
1.4K 44.0 123.0 1.68 MB

The Node.js ⇆ Objective-C bridge

Home Page: http://tootallnate.github.io/NodObjC

License: MIT License

Makefile 0.64% JavaScript 99.13% Shell 0.23%

nodobjc's Introduction

NodObjC

The Node.jsObjective-C bridge

Build Status

NodObjC exposes the Objective-C runtime to Node.js in a high-level, easy to use fashion. It uses the BridgeSupport files to dynamically generate an API from an Objective-C "Framework", and uses the node ffi module to dynamically interact with the Objective-C runtime.

Essentially, NodObjC is similar in nature to the other popular Objective-C scripting bridges:

So you can write entire Cocoa or iOS GUI applications entirely in Node.js JavaScript! Applications are interpreted at runtime through the V8 engine, rather than (pre)compiled to a (binary) machine exectuable. This has the advantage of being able to tweak code without having to recompile; excellent for rapid prototyping and development (or for those GUI applications where absolute speed is not a requirement, i.e. most). So what are you waiting for? Get to coding!

Installation

Install using npm, of course!

$ npm install nodobjc

Or add it to the "dependencies" section of your package.json file.

Hello World

var $ = require('nodobjc')

// First you import the "Foundation" framework
$.framework('Foundation')

// Setup the recommended NSAutoreleasePool instance
var pool = $.NSAutoreleasePool('alloc')('init')

// NSStrings and JavaScript Strings are distinct objects, you must create an
// NSString from a JS String when an Objective-C class method requires one.
var string = $.NSString('stringWithUTF8String', 'Hello Objective-C World!')

// Print out the contents (toString() ends up calling [string description])
console.log(string)
//   → Prints "Hello Objective-C World!"

pool('drain')

Be sure to check out the full API docs.

Introduction

This module offers a bi-directional bridge between Node.js and the Objective-C runtime. What does that mean exactly? Well due to the design of the Objective-C runtime, it is possible to port the entire API to other languages. There are quite a few bridges for Obj-C so one for node was a necessity.

So with this module, you get access to all of the Objective-C APIs, but you invoke them through JavaScript. Obj-C has a concept of "message passing" to invoke methods on objects. The way that you pass messages around is probably a little bit different than the kind of JavaScript you're used to:

// In JavaScript, you invoke a function on an object like:
obj.func(arg)

Compared to:

// In NodObjC, you send a message to an object like:
obj('func', arg)

In Objective-C, the names of methods are part of the arguments that you pass along:

[array insertObject: obj
       atIndex: 5]

The equivalent of the above message invocation in NodObjC syntax would be:

array('insertObject', obj,
      'atIndex', 5)

So the even numbered arguments are the parts of the method name that will be invoked, and the odd numbered arguments are the Obj-C arguments themselves. In the above example, the insertObject:atIndex: function will be invoked.

In NodObjC, not only is the Objective-C runtime exposed, but so are the corresponding C functions that usually go along with these APIs (thanks to BridgeSupport). So for example, we can make an NSRect by calling the NSMakeRect() C function:

$.NSMakeRect(5, 10, 8, 30)
// -> NSRect struct

There's a plethora of other Objective-C resources and tutorials out there.

You should definitely have Apple's official Mac or iOS API docs handy at all times.

Support / Getting Involved

If you're looking for support for developing with/for NodObjC you might want to join the mailing list, and check out the #nodobjc channel in the Freenode IRC server.

Additional topics of discussion can be found on the Wiki page.

nodobjc's People

Contributors

aredridel avatar bernhard-42 avatar mralexgray avatar prayagverma avatar rvlasveld avatar sakisakira avatar shanewholloway avatar tootallnate avatar trevorlinton avatar unboundmusic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nodobjc's Issues

Add note in documentation: Assertion failed: (!handle.IsEmpty()), function Unwrap, file libraries/node/src/node_object_wrap.h, line 60.

Javascript functions being executed from callbacks in obj-c (whether its function blocks, function pointers, extended/derived classes or anything where obj-c calls javascript) if there's an error in the javascript code instead of seeing the error stack trace the program quits on a assertion failure (see title).

A few options, one is to warn users about this in the docs (as try/catch blocks add performance penalties). Or wrap all callback's in a try/catch block and print the stack trace error and potentially process.exit(1).

I thought i'd leave this here to see what the consensus around this is or if there's anyway of propogating callback's stack trace back to the global context in V8.

Thoughts?

Docs

C'mon Nate, people need this stuff...

Planning on using TJ's dox...

Implement Class#addProtocol

Would it be possible to implement Class#addProtocol? I see a failing test and some docs.

I'm trying to work with JavaScriptCore. Some functionality checks to see if a class implements JSExport, an empty protocol. It doesn't appear that it's currently possible to do this with NodObjC.

Thanks.

NodObjC Freezes on app('run').

I've created a simple app from a blog on the net & a stack overflow question:

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

var pool = $.NSAutoreleasePool('alloc')('init'),
    app  = $.NSApplication('sharedApplication'),
    statusMenu;


// set up the app delegate
var AppDelegate = $.NSObject.extend('AppDelegate')
AppDelegate.addMethod('applicationDidFinishLaunching:', 'v@:@', function (self, _cmd, notif) {
  var systemStatusBar = $.NSStatusBar('systemStatusBar');
  statusMenu = systemStatusBar('statusItemWithLength', $.NSVariableStatusItemLength);
  statusMenu('retain');
  var title = $.NSString('stringWithUTF8String', "Hello World");
  statusMenu('setTitle', title);
})

AppDelegate.register()


var delegate = AppDelegate('alloc')('init')
app('setDelegate', delegate)
app('activateIgnoringOtherApps', true)
console.log("Begin");
app('run')
console.log("End");
pool('release');

If I run this I get Begin without an End. So there's a freeze at the line app('run'). I have reason to believe this snippet of code used to work but now its behaving this way.

`npm install` works on 0.10.38, but fails on iojs 1.8.1 and node 0.12.2

NodObjC master » node -v
v1.8.1

NodObjC master » npm i
npm WARN prefer global [email protected] should be installed with -g

> [email protected] install /Users/z/forks/NodObjC/node_modules/memwatch
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

  CXX(target) Release/obj.target/memwatch/src/heapdiff.o
In file included from ../src/heapdiff.cc:5:
../src/heapdiff.hh:14:35: error: expected class name
    class HeapDiff : public node::ObjectWrap
                                  ^
../src/heapdiff.hh:19:49: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
        static v8::Handle<v8::Value> New( const v8::Arguments& args );
                                                ^~~~~~~~~~~~~
                                                v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/heapdiff.cc:5:
../src/heapdiff.hh:20:49: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
        static v8::Handle<v8::Value> End( const v8::Arguments& args );
                                                ^~~~~~~~~~~~~
                                                v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/heapdiff.cc:30:34: error: member initializer 'ObjectWrap' does not name a non-static data member or base class
heapdiff::HeapDiff::HeapDiff() : ObjectWrap(), before(NULL), after(NULL),
                                 ^~~~~~~~~~~~
../src/heapdiff.cc:51:21: error: calling a protected constructor of class 'v8::HandleScope'
    v8::HandleScope scope;
                    ^
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:879:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/heapdiff.cc:52:67: error: cannot initialize a parameter of type 'v8::Isolate *' with an lvalue of type
      'v8::Handle<v8::Value> (const v8::internal::Arguments &)'
    v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(New);
                                                                  ^~~
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:3843:16: note: passing argument to parameter 'isolate' here
      Isolate* isolate,
               ^
../src/heapdiff.cc:54:29: error: no member named 'NewSymbol' in 'v8::String'
    t->SetClassName(String::NewSymbol("HeapDiff"));
                    ~~~~~~~~^
../src/heapdiff.cc:56:41: error: cannot initialize a parameter of type 'v8::FunctionCallback' (aka 'void (*)(const
      FunctionCallbackInfo<v8::Value> &)') with an lvalue of type 'v8::Handle<v8::Value> (const v8::internal::Arguments &)': type
      mismatch at 1st parameter ('const FunctionCallbackInfo<v8::Value> &' vs 'const v8::internal::Arguments &')
    NODE_SET_PROTOTYPE_METHOD(t, "end", End);
                                        ^~~
/Users/z/.node-gyp/1.8.1/src/node.h:226:60: note: passing argument to parameter 'callback' here
                                      v8::FunctionCallback callback) {
                                                           ^
../src/heapdiff.cc:58:29: error: no member named 'NewSymbol' in 'v8::String'
    target->Set(v8::String::NewSymbol( "HeapDiff"), t->GetFunction());
                ~~~~~~~~~~~~^
../src/heapdiff.cc:62:32: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
heapdiff::HeapDiff::New (const v8::Arguments& args)
                               ^~~~~~~~~~~~~
                               v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/heapdiff.cc:67:14: error: member access into incomplete type 'const v8::internal::Arguments'
    if (!args.IsConstructCall()) {
             ^
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: forward declaration of 'v8::internal::Arguments'
class Arguments;
      ^
../src/heapdiff.cc:70:17: error: no member named 'New' in 'v8::String'; did you mean simply 'New'?
                String::New("Use the new operator to create instances of this object.")));
                ^~~~~~~~~~~
                New
../src/heapdiff.cc:62:21: note: 'New' declared here
heapdiff::HeapDiff::New (const v8::Arguments& args)
                    ^
../src/heapdiff.cc:70:29: error: reference to type 'const v8::internal::Arguments' could not bind to an lvalue of type
      'const char [57]'
                String::New("Use the new operator to create instances of this object.")));
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/heapdiff.cc:62:47: note: passing argument to parameter 'args' here
heapdiff::HeapDiff::New (const v8::Arguments& args)
                                              ^
../src/heapdiff.cc:73:21: error: calling a protected constructor of class 'v8::HandleScope'
    v8::HandleScope scope;
                    ^
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:879:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/heapdiff.cc:77:11: error: no member named 'Wrap' in 'heapdiff::HeapDiff'
    self->Wrap(args.This());
    ~~~~  ^
../src/heapdiff.cc:77:20: error: member access into incomplete type 'const v8::internal::Arguments'
    self->Wrap(args.This());
                   ^
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: forward declaration of 'v8::internal::Arguments'
class Arguments;
      ^
../src/heapdiff.cc:82:38: error: no member named 'TakeSnapshot' in 'v8::HeapProfiler'
    self->before = v8::HeapProfiler::TakeSnapshot(v8::String::New(""));
                   ~~~~~~~~~~~~~~~~~~^
../src/heapdiff.cc:82:51: error: no member named 'New' in 'v8::String'; did you mean simply 'New'?
    self->before = v8::HeapProfiler::TakeSnapshot(v8::String::New(""));
                                                  ^~~~~~~~~~~~~~~
                                                  New
../src/heapdiff.cc:62:21: note: 'New' declared here
heapdiff::HeapDiff::New (const v8::Arguments& args)
                    ^
../src/heapdiff.cc:82:67: error: reference to type 'const v8::internal::Arguments' could not bind to an lvalue of type
      'const char [1]'
    self->before = v8::HeapProfiler::TakeSnapshot(v8::String::New(""));
                                                                  ^~
../src/heapdiff.cc:62:47: note: passing argument to parameter 'args' here
heapdiff::HeapDiff::New (const v8::Arguments& args)
                                              ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/memwatch/src/heapdiff.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:169:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1009:12)
gyp ERR! System Darwin 14.1.1
gyp ERR! command "/usr/local/bin/iojs" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/z/forks/NodObjC/node_modules/memwatch
gyp ERR! node -v v1.8.1
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok 
npm WARN excluding symbolic link lib/index.js -> jade.js

> [email protected] install /Users/z/forks/NodObjC/node_modules/libxmljs
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

  CXX(target) Release/obj.target/xmljs/src/libxmljs.o
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:11:34: error: expected class name
class XmlDocument : public node::ObjectWrap {
                                 ^
../src/xml_document.h:42:44: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> New(const v8::Arguments& args);
                                           ^~~~~~~~~~~~~
                                           v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:43:49: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> FromHtml(const v8::Arguments& args);
                                                ^~~~~~~~~~~~~
                                                v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:44:48: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> FromXml(const v8::Arguments& args);
                                               ^~~~~~~~~~~~~
                                               v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:45:47: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> SetDtd(const v8::Arguments& args);
                                              ^~~~~~~~~~~~~
                                              v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:48:45: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Root(const v8::Arguments& args);
                                            ^~~~~~~~~~~~~
                                            v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:49:49: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Encoding(const v8::Arguments& args);
                                                ^~~~~~~~~~~~~
                                                v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:50:48: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Version(const v8::Arguments& args);
                                               ^~~~~~~~~~~~~
                                               v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:51:44: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Doc(const v8::Arguments& args);
                                           ^~~~~~~~~~~~~
                                           v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:52:47: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Errors(const v8::Arguments& args);
                                              ^~~~~~~~~~~~~
                                              v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:53:49: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> ToString(const v8::Arguments& args);
                                                ^~~~~~~~~~~~~
                                                v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:54:49: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Validate(const v8::Arguments& args);
                                                ^~~~~~~~~~~~~
                                                v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:30:9: error: use of undeclared identifier 'Ref'; did you mean 'ref'?
        Ref();
        ^~~
        ref
../src/xml_document.h:29:10: note: 'ref' declared here
    void ref() {
         ^
../src/xml_document.h:34:9: error: use of undeclared identifier 'Unref'; did you mean 'unref'?
        Unref();
        ^~~~~
        unref
../src/xml_document.h:33:10: note: 'unref' declared here
    void unref() {
         ^
In file included from ../src/libxmljs.cc:9:
../src/xml_node.h:9:30: error: expected class name
class XmlNode : public node::ObjectWrap {
                             ^
../src/xml_node.h:25:44: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Doc(const v8::Arguments& args);
                                           ^~~~~~~~~~~~~
                                           v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:9:
../src/xml_node.h:26:50: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Namespace(const v8::Arguments& args);
                                                 ^~~~~~~~~~~~~
                                                 v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:9:
../src/xml_node.h:27:51: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Namespaces(const v8::Arguments& args);
                                                  ^~~~~~~~~~~~~
                                                  v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/libxmljs.cc:9:
../src/xml_node.h:28:47: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
    static v8::Handle<v8::Value> Parent(const v8::Arguments& args);
                                              ^~~~~~~~~~~~~
                                              v8::internal::Arguments
/Users/z/.node-gyp/1.8.1/deps/v8/include/v8.h:134:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/xmljs/src/libxmljs.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:169:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1009:12)
gyp ERR! System Darwin 14.1.1
gyp ERR! command "/usr/local/bin/iojs" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/z/forks/NodObjC/node_modules/libxmljs
gyp ERR! node -v v1.8.1
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok 
npm WARN deprecated [email protected]: This project is long out of date. Use 'marked' instead.

> [email protected] install /Users/z/forks/NodObjC/node_modules/ref
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

  CXX(target) Release/obj.target/binding/src/binding.o
  SOLINK_MODULE(target) Release/binding.node
  SOLINK_MODULE(target) Release/binding.node: Finished

> [email protected] install /Users/z/forks/NodObjC/node_modules/ffi
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

  CC(target) Release/obj.target/ffi/deps/libffi/src/prep_cif.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/types.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/raw_api.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/java_raw_api.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/closures.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffi.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffi64.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/x86/darwin.o
  CC(target) Release/obj.target/ffi/deps/libffi/src/x86/darwin64.o
  LIBTOOL-STATIC Release/libffi.a
  CXX(target) Release/obj.target/ffi_bindings/src/ffi.o
  CXX(target) Release/obj.target/ffi_bindings/src/callback_info.o
  CXX(target) Release/obj.target/ffi_bindings/src/threaded_callback_invokation.o
  SOLINK_MODULE(target) Release/ffi_bindings.node
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame
  SOLINK_MODULE(target) Release/ffi_bindings.node: Finished
npm ERR! Darwin 14.1.1
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "i"
npm ERR! node v1.8.1
npm ERR! npm  v2.8.3
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the memwatch package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls memwatch
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/z/forks/NodObjC/npm-debug.log

NodObjC master » 

import dies when provided framework path has trailing slash

if one attempts to import a framework and provides a full path with a trailing slash, NodObjC expands it out improperly.

$.import('/JUNK/Build/Products/Debug/PonyExpress.framework/');

results in:

Error: Dynamic Linking Error: dlopen(/JUNK/Build/Products/Debug/PonyExpress.framework/PonyExpress.framework/, 2): image not found

ivar("name") not working for imported frameworks

I imported a framework (CocoaHTTPServer) and needed to access an instance variable.
To get it working I had to add

else if (basetype[0] == '@') return createObject(val, '@');

to

function wrapValue (val, type) 

in core.js line 183

Reason: The instance variable came back with type '@"HTTPMessage"' and not only with '@'
By checking only character 0 for '@', I could force to call 'createObject' with basetype "@"
Not sure this is correct, but it worked for me ...

feedback: revert the `addMethod()`, `addClassMethod()`, `addInstanceMethod()` changes?

I have some beef with the new addClassMethod() and addInstanceMethod() functions...

Firstly they're almost identical code except for one call to object_getClass() in the addClassMethod() case. Not very DRY.

Secondly I don't really think there's a need for them except possibly for an easier experience for the user. Previously we could already add a class method by doing something like NSMyClass.getClass().addMethod(...) (i.e. add an instance method to the class' metaclass). Now this requires a bit of knowledge of how the Objective-C runtime works, so that's why an addClassMethod() does kinda make sense to me, however I think it could be implemented as simply as:

  Class.prototype.addClassMethod = function(sel, type, func) {
    this.getClass().addMethod(sel, type, func);
    return this;
  }

Any comments @trevorlinton?

Compiling with nw-gyp?

Hey Nate!

I have no experience with using node-gyp or building a node module. I'm confused as to if there is a source that isn't in the repo.

I attempted to rebuild NodObjC but I kept running into errors (no binding.gyp file).

Anyway! In order to get a module osx-background working with node-webkit I need a version of NodObjC that is compiled with https://github.com/rogerwang/nw-gyp.

This should fix the issue I'm having nwjs/nw.js#1277 (comment).

Rodger the maintainer of both nw-gyp and node-webkit states that NodObjC needs to be built for node-webkit natively.

https://github.com/rogerwang/node-webkit/wiki/Build-native-modules-with-nw-gyp

But this is still an icky issue because then I'll have to create a new versions of both modules webkit-NodObjC and webkit-osx-background or is their some way during npm install that I can specify which to use node-gyp or nw-gyp?

Sorry to bug you with this, I saw somewhere that you stated this should be fixed on the node-webkit end of things?

Using Delegates in NodObjC

Hey guys,

Firstly I want it to be know how impressed I am with NodObjC - great work guys!

Basically my issue is this, I am trying to set a set up a delegate method. Below is an example of what I am trying to achieve in ObjC:

@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate> {

The important part to note is the NSWindowDelegate part. I would then want to specify the following method using AppDelegate.addMethod('performDragOperation:', 'v@:@', function (self, _cmd, sender) {

Am I missing anything that could achieve this? I see in your docs you have Class#addProtocol() on the following page: http://tootallnate.github.io/NodObjC/class.html
This however gives me error stating that addProtocol is undefined...

Any help would be greatly appreciated!

Can NodObjC Handle the Event Type?

I am trying to duplicate the following python:

# PyObjC-related imports
import objc
from Foundation import *
from AppKit import *
from PyObjCTools import AppHelper

KEY_UP = 11

class KeySocketApp(NSApplication):

    def sendEvent_(self, event):
        if event.type() is NSSystemDefined and event.subtype() is 8:
            data = event.data1()
            keyCode = (data & 0xFFFF0000) >> 16
            keyFlags = (data & 0x0000FFFF)
            keyState = (keyFlags & 0xFF00) >> 8
            keyRepeat = keyFlags & 0x1

            self.callback(keyCode, keyState)

        NSApplication.sendEvent_(self, event)


if __name__ == '__main__':


    def callback(code, state):
        if state is KEY_UP:
            print str(code)

    app = KeySocketApp.sharedApplication()
    app.callback = callback
    AppHelper.runEventLoop()

So far I have the following JS:

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

var pool = $.NSAutoreleasePool('alloc')('init'),
    app  = $.NSApplication('sharedApplication');

// set up the app delegate
var AppDelegate = $.NSObject.extend('AppDelegate')

AppDelegate.addMethod('sendEvent_:', 'v', function (self, event) {
  console.log(event);
  app.sendEvent_();
})

AppDelegate.register()

var delegate = AppDelegate('alloc')('init');
app('setDelegate', delegate);
app('activateIgnoringOtherApps', true);
app('run');
pool('release');

Segmentation fault on manual/testapp.js periodically

This is an intermintent issue, sometimes it will, sometimes it wont. Possibly due to node's event loop not integrated into the application callback. However curious if this could be possibly a V8 GC issue, looking to create a more automated unit test of the failure (that's statistically relevant or predictable).

test/extend.js crashing with Bus error: 10

./test/run.sh test/extend.js

   extend.js ./test/run.sh: line 4: 67899 Bus error: 10

In the console.log:

10/15/12 9:25:55.000 AM kernel[0]: Data/Stack execution not permitted: node[pid 67899] at virtual address 0x102a83000, protections were read-write

The crash report:

Process:         node [67899]
Path:            /usr/local/bin/node
Identifier:      node
Version:         ???
Code Type:       X86-64 (Native)
Parent Process:  bash [67898]
User ID:         1822561186

Date/Time:       2012-10-15 09:25:55.135 -0700
OS Version:      Mac OS X 10.8.2 (12C60)
Report Version:  10
Sleep/Wake UUID: 71F47080-F03F-430B-A4BB-3F464DE1B05B

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000102a83120

VM Regions Near 0x102a83120:
    MALLOC_TINY            0000000102700000-0000000102a00000 [ 3072K] rw-/rwx SM=PRV  
--> MALLOC_TINY            0000000102a00000-0000000102b00000 [ 1024K] rw-/rwx SM=COW  
    MALLOC_LARGE           0000000102b00000-0000000102c00000 [ 1024K] rw-/rwx SM=PRV  

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   ???                             0x0000000102a83120 0 + 4339544352
1   ???                             0x0000000102a827e0 0 + 4339541984

Thread 1:: SamplerThread
0   libsystem_kernel.dylib          0x00007fff8624b386 __semwait_signal + 10
1   libsystem_c.dylib               0x00007fff880ea800 nanosleep + 163
2   libsystem_c.dylib               0x00007fff880ea717 usleep + 54
3   node                            0x00000001003948a9 v8::internal::SamplerThread::Run() + 127
4   node                            0x0000000100393b4d v8::internal::ThreadEntry(void*) + 61
5   libsystem_c.dylib               0x00007fff88060742 _pthread_start + 327
6   libsystem_c.dylib               0x00007fff8804d181 thread_start + 13

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x0000000000000002  rcx: 0x000020bb886044f1  rdx: 0x0000000000000018
  rdi: 0x0000000102a36e00  rsi: 0x00007fff875a9cc0  rbp: 0x00007fff5fbfedf0  rsp: 0x00007fff5fbfede8
   r8: 0x0000000000000000   r9: 0x000038aeef8a7339  r10: 0x0000000102a83700  r11: 0x0000000102a83120
  r12: 0xffffffffffffffff  r13: 0x0000000000000001  r14: 0x0000000000000000  r15: 0x00007fff5fbfedf0
  rip: 0x0000000102a83120  rfl: 0x0000000000010246  cr2: 0x0000000102a83120
Logical CPU: 4

Binary Images:
       0x100000000 -        0x1005befff +node (???) <C022726C-5D50-3128-8B8B-FD1ADB5573E4> /usr/local/bin/node
       0x1009f6000 -        0x1009f7fff  Foundation.dylib (72) <559C5AA5-AC7B-3E38-B085-AD09E9FB4D4A> /System/Library/Frameworks/Foundation.framework/Resources/BridgeSupport/Foundation.dylib
       0x1009fc000 -        0x1009fcfff  CFNetwork.dylib (72) <43FE215F-9FE3-3AD7-BD86-9F9EF722F085> /System/Library/Frameworks/CFNetwork.framework/Resources/BridgeSupport/CFNetwork.dylib
       0x100bba000 -        0x100bc5ff7 +ffi_bindings.node (0) <B41A41D2-24A7-33C5-BE7A-9355499FA66B> /Users/USER/*/ffi_bindings.node
       0x100bd0000 -        0x100bdafff +libxmljs.node (0) <A1EF1AA1-933D-323E-9A73-CBEA0FF95D4C> /Users/USER/*/libxmljs.node
       0x100be7000 -        0x100be7ff7  CoreFoundation.dylib (72) <1098EF51-8F87-3F96-BAC3-7FE2F30A1CEE> /System/Library/Frameworks/CoreFoundation.framework/Resources/BridgeSupport/CoreFoundation.dylib
       0x100bec000 -        0x100becff7  IOKit.dylib (72) <EA3AED5F-73C3-3EDB-90F4-251292E4FD8B> /System/Library/Frameworks/IOKit.framework/Resources/BridgeSupport/IOKit.dylib
    0x7fff63162000 -     0x7fff6319693f  dyld (210.2.3) <A40597AA-5529-3337-8C09-D8A014EB1578> /usr/lib/dyld
    0x7fff8260e000 -     0x7fff82615fff  com.apple.NetFS (5.0 - 4.0) <82E24B9A-7742-3DA3-9E99-ED267D98C05E> /System/Library/Frameworks/NetFS.framework/Versions/A/NetFS
    0x7fff82616000 -     0x7fff8284bff7  com.apple.CoreData (106.1 - 407.7) <24E0A6B4-9ECA-3D12-B26A-72B9DCF09768> /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
    0x7fff828af000 -     0x7fff828bbfff  com.apple.CrashReporterSupport (10.8.2 - 415) <55783BF9-125E-3F9C-A412-6A095ECD9353> /System/Library/PrivateFrameworks/CrashReporterSupport.framework/Versions/A/CrashReporterSupport
    0x7fff828bc000 -     0x7fff828bdff7  libremovefile.dylib (23.1) <DBBFAF35-AC78-3856-92F6-6E4FD9DF14A2> /usr/lib/system/libremovefile.dylib
    0x7fff828c1000 -     0x7fff829beff7  libxml2.2.dylib (22.3) <47B09CB2-C636-3024-8B55-6040F7829B4C> /usr/lib/libxml2.2.dylib
    0x7fff82ab0000 -     0x7fff82aefff7  com.apple.QD (3.42 - 285) <8DF36FCA-C06B-30F4-A631-7BE2FF7E56D1> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/QD.framework/Versions/A/QD
    0x7fff83b4d000 -     0x7fff83b91fff  libcups.2.dylib (327) <9B3F3321-D2BC-3195-BF20-4008FC52A390> /usr/lib/libcups.2.dylib

Fails on node-gyp rebuild

Howdy @TooTallNate!!

Looks like I've stumbled upon another one of your sweet packages. This error came up when I tried to install I was wondering if you were aware / knew why. I was just following this tutorial on mac status bar apps. Thanks a bunch, hope all is well!!

thomas@workstation:menubar$ sudo npm install NodObjC
Password:
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm info trying registry request attempt 1 at 11:36:15
npm http GET http://registry.npmjs.org/NodObjC
npm http 304 http://registry.npmjs.org/NodObjC
npm info install [email protected] into /Users/thomas
npm info installOne [email protected]
npm info /Users/thomas/node_modules/NodObjC unbuild
npm info preinstall [email protected]
npm info trying registry request attempt 1 at 11:36:16
npm http GET http://registry.npmjs.org/ffi
npm info trying registry request attempt 1 at 11:36:16
npm http GET http://registry.npmjs.org/debug
npm info trying registry request attempt 1 at 11:36:16
npm http GET http://registry.npmjs.org/ref
npm info trying registry request attempt 1 at 11:36:16
npm http GET http://registry.npmjs.org/ref-struct
npm http 304 http://registry.npmjs.org/debug
npm http 304 http://registry.npmjs.org/ref
npm http 304 http://registry.npmjs.org/ffi
npm http 304 http://registry.npmjs.org/ref-struct
npm info install [email protected] into /Users/thomas/node_modules/NodObjC
npm info install [email protected] into /Users/thomas/node_modules/NodObjC
npm info install [email protected] into /Users/thomas/node_modules/NodObjC
npm info install [email protected] into /Users/thomas/node_modules/NodObjC
npm info installOne [email protected]
npm info installOne [email protected]
npm info installOne [email protected]
npm info installOne [email protected]
npm info /Users/thomas/node_modules/NodObjC/node_modules/debug unbuild
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref unbuild
npm info /Users/thomas/node_modules/NodObjC/node_modules/ffi unbuild
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref-struct unbuild
npm info preinstall [email protected]
npm info preinstall [email protected]
npm info trying registry request attempt 1 at 11:36:16
npm http GET http://registry.npmjs.org/ms
npm http 304 http://registry.npmjs.org/ms
npm info install [email protected] into /Users/thomas/node_modules/NodObjC/node_modules/ref-struct
npm info installOne [email protected]
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref-struct/node_modules/debug unbuild
npm info install [email protected] into /Users/thomas/node_modules/NodObjC/node_modules/debug
npm info installOne [email protected]
npm info /Users/thomas/node_modules/NodObjC/node_modules/debug/node_modules/ms unbuild
npm info preinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/debug/node_modules/ms
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/debug
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info preinstall [email protected]
npm info install [email protected] into /Users/thomas/node_modules/NodObjC/node_modules/ref-struct/node_modules/debug
npm info installOne [email protected]
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref-struct/node_modules/debug/node_modules/ms unbuild
npm info preinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ref-struct/node_modules/debug/node_modules/ms
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ref-struct/node_modules/debug
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ref-struct
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info preinstall [email protected]
npm info trying registry request attempt 1 at 11:36:17
npm http GET http://registry.npmjs.org/bindings
npm info trying registry request attempt 1 at 11:36:17
npm http GET http://registry.npmjs.org/nan
npm http 304 http://registry.npmjs.org/bindings
npm http 304 http://registry.npmjs.org/nan
npm info install [email protected] into /Users/thomas/node_modules/NodObjC/node_modules/ref
npm info install [email protected] into /Users/thomas/node_modules/NodObjC/node_modules/ref
npm info install [email protected] into /Users/thomas/node_modules/NodObjC/node_modules/ref
npm info installOne [email protected]
npm info installOne [email protected]
npm info installOne [email protected]
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/debug unbuild
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/bindings unbuild
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/nan unbuild
npm info preinstall [email protected]
npm info preinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/bindings
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info install [email protected] into /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/debug
npm info installOne [email protected]
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/debug/node_modules/ms unbuild
npm info preinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/debug/node_modules/ms
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/debug
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info preinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ref/node_modules/nan
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ref
npm info linkStuff [email protected]
npm info install [email protected]

> [email protected] install /Users/thomas/node_modules/NodObjC/node_modules/ref
> node-gyp rebuild

gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn python
gyp info spawn args [ '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
   '-I', spawn args-
gyp info spawn args   '/Users/thomas/node_modules/NodObjC/node_modules/ref/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/thomas/.node-gyp/0.11.12/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/thomas/.node-gyp/0.11.12',
gyp info spawn args   '-Dmodule_root_dir=/Users/thomas/node_modules/NodObjC/node_modules/ref',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
/

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.


\
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
-

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.


gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 69
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:107:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1045:12)
gyp ERR! System Darwin 13.3.0
command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/thomas/node_modules/NodObjC/node_modules/ref
gyp ERR! node -v v0.11.12
gyp ERR! node-gyp -v v0.13.1
gyp ERR! not ok 
npm info preinstall [email protected]
npm info install [email protected] into /Users/thomas/node_modules/NodObjC/node_modules/ffi
npm info installOne [email protected]
npm info /Users/thomas/node_modules/NodObjC/node_modules/ffi/node_modules/bindings unbuild
npm info preinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ffi/node_modules/bindings
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info build /Users/thomas/node_modules/NodObjC/node_modules/ffi
npm info linkStuff [email protected]
npm info install [email protected]
npm info [email protected] Failed to exec install script
npm info /Users/thomas/node_modules/NodObjC/node_modules/ref unbuild
npm info preuninstall [email protected]

> [email protected] install /Users/thomas/node_modules/NodObjC/node_modules/ffi
> node-gyp rebuild

|
node.js:709
    var cwd = process.cwd();
                      ^
Error: ENOENT, no such file or directory
    at Function.startup.resolveArgv0 (node.js:709:23)
    at startup (node.js:63:13)
    at node.js:803:3
npm info uninstall [email protected]
npm info postuninstall [email protected]
npm info /Users/thomas/node_modules/NodObjC unbuild
npm info preuninstall [email protected]
npm info uninstall [email protected]
npm info postuninstall [email protected]
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the ref package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls ref
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "NodObjC"
npm ERR! cwd /Users/thomas/Desktop/menubar
npm ERR! node -v v0.11.12
npm ERR! npm -v 1.4.14
npm ERR! code ELIFECYCLE
npm info [email protected] Failed to exec install script
npm info /Users/thomas/node_modules/NodObjC/node_modules/ffi unbuild
npm info preuninstall [email protected]
npm info uninstall [email protected]
npm info postuninstall [email protected]
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/thomas/Desktop/menubar/npm-debug.log
npm ERR! not ok code 0

hello! how to use ffi moudle link a dll file?

typedef struct _LogInfo
{
char severip[16];
int severport;
char severid[24];
char localip[16];
int localport;
char username[24];
char password[64];
int keepalive;
int timeout;
int expires;
}LogInfo;

typedef void (*Callback_Offline)( void *userdata );

int GBAPI NP_GB_Login( void* userdata, LogInfo &info, Callback_Offline callback );

My nodejs code is:

var SDKHandle = ffi.Library('./gbsdk-console', {
'NP_GB_Init': ['void', []],
'NP_GB_Login': ['int', ['void',_LogInfoPtr,voidptr]]
});

var logInfo= new Buffer(164);
logInfo.write("192.168.60.107\0\0",0,16);
logInfo.writeInt32LE(5060,16);
logInfo.write("15000000002000000001\0\0\0\0",20,24);
logInfo.write("192.168.60.46\0\0",44,16);
logInfo.writeInt32LE(81,60);
logInfo.write("15000000004000000003\0\0\0\0",64,24);
logInfo.write("123456\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",88,64);
logInfo.writeInt32LE(60,152);
logInfo.writeInt32LE(3,156);
logInfo.writeInt32LE(3600,160);

SDKHandle.NP_GB_Init();

var N=SDKHandle.NP_GB_Login("null",logInfo,Callback_Offline);
console.log(N);

NP_GB_Login is all right, but the callback is not run!

I wang get the answer,thanks!

modal behavior differs from PyObjC

Given equivalent code, PyObjC and NodObjC have different behavior. In PyObjC modal windows come to the front, as expected. In NodObjC the same window stays at the bottom of the stack and cannot be focused.

NodObjC---

var $ = require('NodObjC');

$.import('IOBluetooth');
$.import('IOBluetoothUI');

var selector = $.IOBluetoothDeviceSelectorController('deviceSelector');
selector('runModal');

PyObC---

IOBluetoothUI.py ====

import objc as _objc                                                                                                                                            
_objc.loadBundle('IOBluetoothUI', globals(),
  bundle_path=u'/System/Library/Frameworks/IOBluetoothUI.framework')

main.py ====

from IOBluetoothUI import *
selector = IOBluetoothDeviceSelectorController.deviceSelector()
selector.runModal()

Module did not self-register

Hi all,
I'm new to nodejs and I'm trying to build an app that include NodObjC and I have a problem when package my app.
I did an "sudo npm install NodObjC" on my workspace, every things seems to work ok. But when I copy the source (include node-modules/NodObjC folder) for packaging, my app crash:

17:28:33.185 ERROR: "CRASH: ", "Module did not self-register."
17:28:33.186 ERROR: "Backtrace:"
17:28:33.186 ERROR: "Error: Module did not self-register."
17:28:33.186 ERROR: " at Error (native)"
17:28:33.186 ERROR: " at Module.load (module.js:354:32)"
17:28:33.186 ERROR: " at Function.Module._load (module.js:310:12)"
17:28:33.186 ERROR: " at Module.require (module.js:362:17)"
17:28:33.186 ERROR: " at require (module.js:378:17)"
17:28:33.186 ERROR: " at bindings (/node_modules/NodObjC/node_modules/ref/node_modules/bindings/bindings.js:76:44)"
17:28:33.187 ERROR: " at Object. (/node_modules/NodObjC/node_modules/ref/lib/ref.js:5:47)"
17:28:33.187 ERROR: " at Module._compile (module.js:454:26)"
17:28:33.187 ERROR: " at Object.Module._extensions..js (module.js:472:10)"
17:28:33.187 ERROR: " at Module.load (module.js:354:32)"

Any help would be appriciated!

Arguments: why not hashes/dictionaries?

Very cool stuff!

Sorry, this is more of a question than an issue, but didn't know where else to ask:

In Objective-C, the names of methods are part of the arguments that you pass
along:

[array insertObject:obj atIndex:5];

The equivalent of the above message invocation in NodObjC syntax would be:

array('insertObject', obj, 'atIndex', 5)

So the even numbered arguments are the parts of the method name that will be
invoked, and the odd numbered arguments are the Obj-C arguments themselves. In
the above example, the insertObject:atIndex: function will be invoked.

How come these arguments aren't just passed as a dictionary instead?

array({
  insertObject: obj,
  atIndex: 5,
});

I'm an Obj-C noob, so apologies if there's an obvious answer and I'm missing it. =)

Great stuff again!

Compiling for node-webkit?

Hi,

This isn't really a bug, I am just unsure of the best place to post this.

I have posted a question over in node-webkit as I am trying to compile nodobjc for use there.

I don't suppose anyone here would be able to give me a hand in getting this running would you? It sounds like it's more an issue with node-ffi.

I'd really appreciate any help anyone could give - thanks!,

Mouse Control Causes Segfaults/Abort Traps

Im trying to write a node js program that can control a mouse using a tessel (tessel.io)

My code for moving the mouse position is

Mouse.prototype.move = function (X, Y) {
  var moveEvent = $.CGEventCreateMouseEvent(null, $.kCGEventMouseMoved, $.CGPointMake(X, Y), 0);
  $.CGEventPost($.kCGHIDEventTap, moveEvent);
}

It works fine for a while but segfaults after its called too many times. (somewhere around 28 times for the test I ran). Im probably doing something wrong, what do you think?

Heres the test I ran

var count = 0;

setInterval(function () {
  console.log(count++);
  mouse.move(1, 1);
}, .00000000001)

and the stacktrace:


* thread #1: tid = 0x2385, 0x00000001009eb7bb ffi_bindings.node`classify_argument(type=<unavailable>, classes=0x00007fff5fbff0a0, byte_offset=<unavailable>) + 363 at ffi64.c:224, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x00000001009eb7bb ffi_bindings.node`classify_argument(type=<unavailable>, classes=0x00007fff5fbff0a0, byte_offset=<unavailable>) + 363 at ffi64.c:224
   221        {
   222          int num;
   223  
-> 224          byte_offset = ALIGN (byte_offset, (*ptr)->alignment);
   225  
   226          num = classify_argument (*ptr, subclasses, byte_offset % 8);
   227          if (num == 0)
(lldb) thread trace
invalid command 'thread trace'
(lldb) thread backtrace
* thread #1: tid = 0x2385, 0x00000001009eb7bb ffi_bindings.node`classify_argument(type=<unavailable>, classes=0x00007fff5fbff0a0, byte_offset=<unavailable>) + 363 at ffi64.c:224, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x00000001009eb7bb ffi_bindings.node`classify_argument(type=<unavailable>, classes=0x00007fff5fbff0a0, byte_offset=<unavailable>) + 363 at ffi64.c:224
    frame #1: 0x00000001009eb0d2 ffi_bindings.node`ffi_call [inlined] examine_argument(type=<unavailable>, in_return=<unavailable>) + 5 at ffi64.c:301
    frame #2: 0x00000001009eb0cd ffi_bindings.node`ffi_call(cif=0x00000001057e1600, fn=0x00007fff83c2ddad, rvalue=<unavailable>, avalue=0x0000000105802eb0) + 509 at ffi64.c:446
    frame #3: 0x00000001009e7d9f ffi_bindings.node`ForeignCaller::Exec(args=<unavailable>) + 399 at foreign_caller.cc:88
    frame #4: 0x000022cdd14ca219
(lldb) 

$.import('AppKit') fails with Cannot call method 'value' of null

System Information

Mac OS X 10.6.8

Test Case

console.log("NodObjCTest - about to load NodObjC");
var $ = require('NodObjC');
console.log("NodObjCTest - done loading NodObjC");
$.import('Foundation');
console.log("NodObjCTest - done importing Foundation");
$.import('AppKit');
console.log("NodObjCTest - done importing AppKit");

Result of Test Case

NodObjCTest - about to load NodObjC
NodObjCTest - done loading NodObjC
NodObjCTest - done importing Foundation

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Cannot call method 'value' of null
    at /Users/fquatro/workspace/homeview-ma/service/target/test-wip/testable/node_modules/NodObjC/lib/bridgesupport.js:58:14
    at /Users/fquatro/workspace/homeview-ma/service/target/test-wip/testable/node_modules/NodObjC/lib/bridgesupport.js:119:53
    at Array.forEach (native)
    at bridgesupport (/Users/fquatro/workspace/homeview-ma/service/target/test-wip/testable/node_modules/NodObjC/lib/bridgesupport.js:100:9)
    at importFramework (/Users/fquatro/workspace/homeview-ma/service/target/test-wip/testable/node_modules/NodObjC/lib/import.js:95:3)
    at /Users/fquatro/workspace/homeview-ma/service/target/test-wip/testable/node_modules/NodObjC/lib/bridgesupport.js:109:9
    at Array.forEach (native)
    at bridgesupport (/Users/fquatro/workspace/homeview-ma/service/target/test-wip/testable/node_modules/NodObjC/lib/bridgesupport.js:100:9)
    at importFramework (/Users/fquatro/workspace/homeview-ma/service/target/test-wip/testable/node_modules/NodObjC/lib/import.js:95:3)
    at /Users/fquatro/workspace/homeview-ma/service/target/test-wip/testable/node_modules/NodObjC/lib/bridgesupport.js:109:9

Other Information

The test case runs fine on OS X 10.7
The test case runs fine on OS X 10.6 with NodObjC 0.0.10

Cannot call UIApplicationMain() internalFieldCount() > 0 assert

I have compiled the nodobjc nodejs module (node-ffi, libxmljs) for iOS, and I'm using it on a jailbreaked iOS 5.0.1. with node from cydia.

The first function to create an iOS app is UIApplicationMain().

This function is described in the BridgeSupport files that can be found here (https://github.com/innoying/iOS-BridgeSupport) (extract the contents of src/ to /).

This is the code i'm trying to run:

  var $ = require('NodObjC')
  $.import ('UIKit')
  var pool = $.NSAutoreleasePool('alloc')('init')
  console.log ($.UIScreen);
  console.log ($.UIApplicationMain);
  var str = $.NSString('stringWithUTF8String', "hello")
  var str2 = $.NSString('stringWithUTF8String', "world")
  var ret = $.UIApplicationMain (0, [], str, str2);
  console.log (ret);
  pool ('release');

This is the output:

$ node uikit.js 
[Class: UIScreen]
{ [Function: unwrapper]
  retval: { type: 'i' },
  args: [ { type: 'i' }, { type: '^*' }, { type: '@' }, { type: '@' } ],
  pointer: <Pointer address="927458049" allocated="0" free="false">,
  info: 
   { _name: 'function',
     name: 'UIApplicationMain',
     args: [ [Object], [Object], [Object], [Object] ],
     retval: { type: 'i' } } }
Assertion failed: (handle->InternalFieldCount() > 0), function Unwrap, file /var/root/.node-gyp/0.6.14/src/node_object_wrap.h, line 52.
Abort trap: 6

Looks like there's a problem trying to unwrap the function arguments. How is ^* (char**) suposed to be used? is this a bug in nodobjc? am i doing something wrong?

Is this still being actively maintained?

Hi,

I've been working heavily in nodobjc for quite a few months and have fixed a vast amount of bugs i've found, including:

  1. Support for node-ffi/ffi 1.0
  2. Structure returned for id/super message sending
  3. Better support for automatic garbage collection of delegates
  4. Less memory overhead using libxmljs to read in frameworks
  5. Integration of node's CF loop without needing uvcf (uvcf is great, but it pushes the clock timer to 0.01 MS and cpu use to 100% after NSApplication run. It also does not adhere to Apple's energy/performance guidelines) and requires a C++ compiled in solution.
  6. Fixed some odds and ends here and there to make code more clear (there was a reference in there where you were writing/reading a variable and in the comments didn't know why but it seg faulted without it, turns out it was a mem alignment issue where the ref wasn't written to the pointer unless it was read first).

I'd like to push these up but the API has changed (very slightly), the dependencies have changed, and I need it (quickly) for a project i'm doing.

I'm considering creating a derived project from nodobjc for the changes i've made so I can get into NPM in the next two-three weeks but I wanted to first check here to see if this is being actively maintained, if so i'll push the changes up here. However if you think this is something you'll not be maintianing actively going forward my company can commit to maintaining its feature set.

I guess i'm asking for your recommendation on what we should do concerning nodobjc. (BTW, any new project we'd be happy to add a disclaimer that its derived work from nodobjc and give you credit, and if the changes are integrated into nodobjc we'd redirect back, or, if you can add us as a contributor/collaborator we can continue to maintain nodobjc through your repo).

Thanks!
Trevor

NSInternalInconsistencyException

with this

var $ = require('NodObjC')

$.framework('Foundation')
$.framework('Cocoa')

var pool = $.NSAutoreleasePool('alloc')('init')
var window = $.NSWindow('alloc')('init')
window('makeKeyAndOrderFront', null)

I get this:

NSInternalInconsistencyException: Error (1000) creating CGSWindow on line 259
    at Function.msgSend (/Volumes/WS/xxx/server/node_modules/NodObjC/lib/id.js:156:21)
    at id (/Volumes/WS/xxx/server/node_modules/NodObjC/lib/id.js:119:15)
    at Object.<anonymous> (/Volumes/WS/xxx/server/cocoa.js:7:33)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Add note in documentation: V8/Objective-C Threading Limitations

This is not so much a bug but perhaps an inherent limitation to V8/Node/Objective-C FFI bridge.

There are rare scenarios in objective-c that will cause deadlocks. [NSData dataWithContentsOfURL: ] is one of them. dataWithContentsOfURL will open a semaphore to block the current main thread while NSURLProtocol will call up the handler for the URL to run. If (in javascript) you've implemented any types of filters with NSURL or a NSURL Protocol class (for a custom protocol) it will cause a dead lock.

Thread A (NSData) is waiting for a response on the data, it issues a semaphore/mutex to pause the thread; all the while Thread B is NSURLProtocol trying to invoke a javascript function to get the data, however ThreadedCallbackInvokation::WaitForExecution on Thread B sits on a mutex waiting for Thread A to unlock. Both Thread A and B are waiting for each other.

The symptoms are a spinning beachball of doom when your application hits the call to get any data.

If there's any ideas of how to get around this via node-ffi/etc please chime in. There are usually work arounds in objective-c but I thought i'd post it here incase someone runs into the same problem.

Doesn't work on Lion

It appears apple removed the "full" BridgeSupport files I was previously relying on. Still working on figuring out the best fix, but I haven't yet figured out how to introspect the metaclass object of an objc class.

On top of no longer including the "full" versions of the BridgeSupport files, the minimal versions they are shipping with Lion are very stripped down for some reason. NSAutoreleasePool for instance isn't even in the Foundation.bridgesupport file, though it is there on my Snow Leopard version...

error setting argument 0 when using CFRelease

I've really enjoyed playing with NodObjC but am stumped by an issue I'm having. I'm creating objects with $.CGEventCreateMouseEvent and want to release them with $.CFRelease as follows:

var $ = require('NodObjC');
$.framework('Cocoa');

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

var moveEvent = $.CGEventCreateMouseEvent(null, $.kCGEventMouseMoved, $.CGPointMake(100, 100), $.kCGMouseButtonLeft);
$.CGEventPost($.kCGHIDEventTap, moveEvent);
$.CFRelease('cf', moveEvent);

pool('drain'); 

But I'm getting the following error:

/Users/owencm/Desktop/node-macmouse/node_modules/ffi/lib/_foreign_function.js:54
      throw e
            ^
TypeError: error setting argument 0 - writePointer: Buffer instance expected as third argument
    at TypeError (native)
    at Object.writePointer (/Users/owencm/Desktop/node-macmouse/node_modules/ffi/node_modules/ref/lib/ref.js:740:11)
    at Object.set (/Users/owencm/Desktop/node-macmouse/node_modules/ffi/node_modules/ref/lib/ref.js:482:13)
    at Object.alloc (/Users/owencm/Desktop/node-macmouse/node_modules/ffi/node_modules/ref/lib/ref.js:514:13)
    at ForeignFunction.proxy (/Users/owencm/Desktop/node-macmouse/node_modules/ffi/lib/_foreign_function.js:49:22)
    at Function.unwrapper (/Users/owencm/Desktop/node-macmouse/node_modules/NodObjC/lib/core.js:297:31)
    at Object.<anonymous> (/Users/owencm/Desktop/node-macmouse/test.js:8:7)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)

I've dug around a little in _foreign_function.js but can't seem to find the problem - is there something I'm doing wrong or is this an actual bug?

TypeError: error setting argument 0 - writePointer: Buffer instance expected as third argument

I've been messing around with your module a little bit recently (very cool module btw), I threw together a simple module, macmouse, that gives you the ability to control your mouse through node.js, now I'm trying to fetch information on open windows via CGWindowListCopyWindowInfo (the idea is to do something fun using that information and the virtual mouse functionality).
I don't have much experience with Objective C but I stumbled upon an example of this in a blog post: http://b2cloud.com.au/tutorial/monitoring-any-window-in-os-x/
I tested it out in Xcode,

#import "Foundation/Foundation.h"
#import "Cocoa/Cocoa.h"

NSArray* windows = CFBridgingRelease(CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
NSLog(@"%@", windows);

and it prints out all the data I want and more, but now I'm stuck on how to do this using the NodObjC module.

Here's my go at it (using NodObjC v1.0.0):

var $ = require('NodObjC');
$.framework('Foundation');
$.framework('Cocoa');
var pool = $.NSAutoreleasePool('alloc')('init');

var windowList = $.CFBridgingRelease($.CGWindowListCopyWindowInfo($.kCGWindowListOptionAll, $.kCGNullWindowID));

console.log(windowList);

pool('drain');

but I'm getting the following error:

/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/lib/_foreign_function.js:55
      throw e
            ^
TypeError: error setting argument 0 - writePointer: Buffer instance expected as third argument
    at Object.writePointer (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:740:11)
    at Object.set (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:482:13)
    at Object.alloc (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:514:13)
    at ForeignFunction.proxy (/Users/loknar/Desktop/node_robot/nodobjc_stuff/ffi/lib/_foreign_function.js:50:22)
    at Function.unwrapper (/Users/loknar/Desktop/nodobjc_stuff/node_modules/NodObjC/lib/core.js:297:31)
    at Object.<anonymous> (/Users/loknar/Desktop/nodobjc_stuff/listOfWindows.js:44:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

Any suggestions, tips or comments are very much appreciated.

edit:
question posted on stackoverflow.

Integrate with node's event loop

This is a tough one... But basically since node maintains it's own event loop, it makes it rather hard to make Objective-C's NSRunLoop or CFRunLoop integrate with it.

Currently, some code as simple as this will crash your terminal tab, since node repl runs in raw mode and we're subsequently starting a new event loop on the main thread, even Ctrl+C won't get you out:

var $ = require('NodObjC')
$.import('Foundation')
$.NSRunLoop('currentRunLoop')('run')

There is only one solution that I can think of: Write a Cocoa backend for libev (or libuv) so that it's underlying event loop is NSRunLoop. So far I have not looked into what that would entail, but I'm assuming it's not a trivial task...

Any additional insight on the subject would be appreciated in the meantime.

/cc @ry

Memory Allocation Problem

The following code example returns 600, rather than the expected value of 500.

var abc = $.NSMakeRect(0, 0, 500, 500);
var abcd = $.NSMakeRect(0, 0, 600, 600);
console.log(abc.size.width);

This also causes a segmentation fault when I click an NSButton that has an action defined (which is set to a javascript-based method I added to the WindowDelegate). However, if I change the above to the following:

var abc = $.NSMakeRect(0, 0, 500, 500);
$.NSMakeRect(0, 0, 600, 600);
console.log(abc.size.width);

The console still prints 600, but the segmentation fault is avoided. Would this be some sort of memory allocation problem, or am I completely misunderstanding how things work?

Thanks for any help you can provide.

implement objc_msgSend_stret

When a objc method returns a structure it should execute obj_msgSend_stret, currently it executes obj_msgSend however.

Apple docs are here: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/doc/c_ref/objc_msgSend_stret

I've changed id.js and core.js to support obj_msgSend_stret, when obj_msgSend executes it checks if the return type is a structure and runs the code below rather than obj_sendMsg, however this segfaults when ffi tries to call it, ideas?

var structRaw = types[0];
var struct  = structure.getStruct(types[0]);
types[1].splice(0, 0, structRaw);
types[0] = 'v';
var argTypes = types[1]
  , msgSendFunc = core.get_objc_msgSend_stret(types)
  , unwrappedArgs = core.unwrapValues([ref.alloc(struct), this, sel].concat(args), argTypes)
  , rtn;

try {
  rtn = msgSendFunc.apply(null, unwrappedArgs)
} catch (e) {
  var err = e
  if (!e.hasOwnProperty('stack')) {
    err = exception.wrap(e)
  }
  throw err
}
// Process the return value into a wrapped value if needed
return core.wrapValue(args[0], types[1]);

NodObjC not installing on iOS

I have installed the node using Cydia. Then i tried installing NodObjC on it but it failed with the following error.

make: Entering directory `/private/var/root/node_modules/NodObjC/node_modules/node-ffi/build'
  ACTION libffi_test .
make[1]: Entering directory `/private/var/root/node_modules/NodObjC/node_modules/node-ffi/deps/libffi'
make[1]: *** No targets specified and no makefile found.  Stop.
make[1]: Leaving directory `/private/var/root/node_modules/NodObjC/node_modules/node-ffi/deps/libffi'
  TOUCH Release/obj.target/libffi.stamp.node
  CXX(target) Release/obj.target/ffi_bindings/src/ffi.o
cc1objplus: error: unrecognized command line option "-arch"
make: *** [Release/obj.target/ffi_bindings/src/ffi.o] Error 1
make: Leaving directory `/private/var/root/node_modules/NodObjC/node_modules/node-ffi/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:219:23)
gyp ERR! stack     at ChildProcess.emit (events.js:70:17)
gyp ERR! stack     at maybeExit (child_process.js:360:16)
gyp ERR! stack     at Process.onexit (child_process.js:396:5)
gyp ERR! System Darwin 11.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /private/var/root/node_modules/NodObjC/node_modules/node-ffi
gyp ERR! node -v v0.6.14
gyp ERR! node-gyp -v v0.6.11
gyp ERR! not ok 
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR! 
npm ERR! Failed at the node-ffi@0.5.5 install script.
npm ERR! This is most likely a problem with the node-ffi package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls node-ffi
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 11.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "NodObjC"
npm ERR! cwd /private/var/root
npm ERR! node -v v0.6.14
npm ERR! npm -v 1.1.62
npm ERR! code ELIFECYCLE
gyp ERR! UNCAUGHT EXCEPTION 
gyp ERR! stack Error: ENOENT, no such file or directory
gyp ERR! stack     at runGyp (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:325:46)
gyp ERR! stack     at Object.oncomplete (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:90:5)
gyp ERR! System Darwin 11.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! Completion callback never invoked! 
gyp ERR! System Darwin 11.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! UNCAUGHT EXCEPTION 
gyp ERR! stack Error: ENOENT, no such file or directory
gyp ERR! stack     at errorMessage (/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js:119:28)
gyp ERR! stack     at issueMessage (/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js:125:3)
gyp ERR! stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js:101:5)
gyp ERR! stack     at EventEmitter.emit (events.js:64:17)
gyp ERR! System Darwin 11.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/root/npm-debug.log
npm ERR! not ok code undefined
npm ERR! not ok code 1

Add note in documentation: Mention that NodObjC apps cannot be approved on app stores

The readme says "you can write entire Cocoa or iOS GUI applications entirely in NodeJS JavaScript!" but fails to mention that such apps will not be approved for distribution on the primary distribution system for iOS or OS X: namely, the Apple app stores. See prior discussion:

https://groups.google.com/forum/#!msg/nodejs/7c_0hkdoEGY/NU9dikAuBhwJ

Please mention prominently in the readme that apps developed with NodObjC will not be approved on Apple app stores, so that developers who are interested in distributing their apps that way will not waste their time investigating NodObjC. Thanks.

Object wrap caching

For all these wrapper pointers, there may be a possibility of keeping a cache of the JS-wrapped objects, and returning those whenever the same pointer is re-encountered to be wrapped.

This would have the benefit of having the same objects pass a strict equality test ===, and keep any monkey-patched additions the user made to an object (in JS-land).

There is one possibility for this, but I'm not sure if it's safe to do yet: Cache based on the pointer's address in memory. It shouldn't change throughout an Obj-C object's lifetime so that's all good. I'm just afraid of after an object is garbage collected in Obj-C-land, how to know to clear the object from the cache there, in case a new object takes that old object's place in memory. Then all kinds of bad would happen...

JavaScriptCore issues

Hello,

JavaScriptCore is a new API that provides some fancy Obj-C JS interaction. Why I want to go Javascript->ObjC->Javascript is a long story.

#import <JavaScriptCore/JavaScriptCore.h>

...

JSContext *con = [[JSContext alloc] init];
NSLog(@"%@", con);
id fun = ^(NSInteger a, NSInteger b) {
    return a + b;
};
NSLog(@"%@", fun);
[con setObject:fun forKeyedSubscript:@"add"];
NSLog(@"%@", [con objectForKeyedSubscript:@"add"]);
JSValue *type = [con evaluateScript:@"typeof add"];
NSLog(@"%@", type);
JSValue *str = [con evaluateScript:@"add.toString()"];
NSLog(@"%@", str);
JSValue *json = [con evaluateScript:@"JSON.stringify(add)"];
NSLog(@"%@", json);

outputs

2015-02-19 08:47:47.419 Test[30470:290959] <JSContext: 0x6000000528d0>
2015-02-19 08:47:47.419 Test[30470:290959] <__NSGlobalBlock__: 0x100002090>
2015-02-19 08:47:47.420 Test[30470:290959] <__NSGlobalBlock__: 0x100002090>
2015-02-19 08:47:47.420 Test[30470:290959] function
2015-02-19 08:47:47.420 Test[30470:290959] function () {
    [native code]
}
2015-02-19 08:47:47.421 Test[30470:290959] undefined

Note that typeof add === 'function'. Now let's look at the NodObjC.

var $ = require('NodObjC')
$.framework('JavaScriptCore')
var con = $.JSContext('alloc')('init')
console.log(con)
var fun = $(function (self, a, b) {
  return a + b
}, ['I', ['?', 'I', 'I']])
console.log(fun)
con('setObject', fun, 'forKeyedSubscript', $('add'))
console.log(con('objectForKeyedSubscript', $('add')))
var type = con('evaluateScript', $('typeof add'))
console.log(type)

outputs

<JSContext: 0x100d07fc0>
<__NSGlobalBlock__: 0x10185c8c0>
<__NSGlobalBlock__: 0x10185c8c0>
object
[object NSBlock]
{}

Now typeof add === 'object' even though the two values in Obj-C are both global blocks.

Is there something wrong with my Block syntax? For some reason, JSC doesn't appear to be recognizing it as a function and converting it to a I'm currently looking into how JSC makes its Obj-C/js translation, and will add more info as I find it.

JSC docs are sparse - here is some info about the translation: http://opensource.apple.com/source/JavaScriptCore/JavaScriptCore-7537.65/API/JSValue.h

Support for "Block" Functions.

Being able to call any function/method that accepts a "Block" parameter should be able to work with a regular JS Function. I just need to figure out how to go from a function pointer to a Block pointer at runtime.

This might be related: http://clang.llvm.org/docs/Block-ABI-Apple.txt

Example (currently segfaults):

var $ = require('NodObjC')
$.import('Foundation')
$.NSAutoreleasePool('alloc')('init')

// Create an NSArray with some random entries
var array = $.NSMutableArray('alloc')('init')
for (var i = 0; i<10; i++) {
  var str = $._(String.fromCharCode(Math.round(Math.random()*26)+('a'.charCodeAt(0))))
  array('addObject', str)
}

// Enumerate using a Block
array('enumerateObjectsUsingBlock', function (obj, index, stopPtr) {
  console.log('%d: %s', index, obj)
})

How to extend NSView, overwrite drawRect

This is not really a bug, but more of a question:

I'm just not able to find out, how to correctly inherit from NSView and overwrite the drawRect method, getting the rect parameter and call drawRect of super. Any help or hint would be welcome!

I extended the basic example by this:

var RedRectView = ObjC.NSView.extend('RedRectView');
RedRectView.addMethod('drawRect:', 'v@:@', function (self, _cmd, rect) {
//  console.log(rect); // already crashes
//  ObjC.NSColor('yellowColor')('set');
//  ObjC.NSRectFill(ObjC.NSRectMake(0,0,100,100));

    // [super drawRect:rect]; // how to call super?
//  RedRectView.getSuperclass()('drawRect', self);
});
RedRectView.register();

var redRectView = RedRectView('alloc')('initWithFrame', ObjC.NSMakeRect(0,0,100,100));
window('contentView')('addSubview', redRectView);
window('makeKeyAndOrderFront', null);

But as soon as I try some of these, the App crashes with a "Segmentation fault: 11".

@try / @catch

I cannot seem to find a way to catch Objective-C runtime exceptions (i.e. [array addObject: nil] ).

This is a big problem.

Note that I have been able to get objc_setUncaughtExceptionHandler working, but I'm not yet sure if it's possible to prevent the process from exiting subsequently...

BOOL comes across as 0/1 int, could be true/false

while not a big deal for truthiness checks, the bridgesupport file does flag BOOL returns and could be nicely massaged into a javascript native true or false value?

…
<class name='PEOSCSender'>
    <method selector='connect'>
        <retval type='B'/>
    </method>
</class>
…

doesn't work with node-ffi v1.0 API

the dependency node-ffi 0.5.4 won't build for me on node 0.8,

also, when I manually switch node-ffi 0.5.4 for 1.0.2, NodObjc doesn't pass its tests, failing with:

core/blocks.js
/Users/justin/dev/NodObjC/lib/core.js:18
, uintptr_t = ffi.Bindings.POINTER_SIZE == 8 ? 'uint64' : 'uint32'
^
TypeError: Cannot read property 'POINTER_SIZE' of undefined
at Object. (/Users/justin/dev/NodObjC/lib/core.js:18:29)

TODO: Support NSDecimal "primitive" type.

This may be an issue in ref-struct, NSDecimal fails to parse into a struct (well it does, but size=0). It's signature looks like this (from method_getReturnTypes) {?=b8b4b1b1b18[8S]}

The definition in apples docs say:

typedef struct {
      signed int _exponent:8;
      unsigned int _length:4;
      unsigned int _isNegative:1;
      unsigned int _isCompact:1;
      unsigned int _reserved:18;
      unsigned short _mantissa[NSDecimalMaxSize];
} NSDecimal;

This is listed as a primitive in the apple docs.. :/

iOS support

We could add iOS support if there were an option to convert Node.js code into pure ObjC.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.