Created
March 10, 2015 14:27
-
-
Save stephenmathieson/6593406b5d791db4345b to your computer and use it in GitHub Desktop.
NanThrowError & iojs 1.5.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <nan.h> | |
using namespace v8; | |
NAN_METHOD(Wut); | |
void | |
Init(Handle<Object> exports){ | |
exports->Set( | |
NanNew<String>("wut") | |
, NanNew<FunctionTemplate>(Wut)->GetFunction() | |
); | |
} | |
NODE_MODULE(wut, Init); | |
NAN_METHOD(Wut){ | |
NanScope(); | |
Local<String> foo; | |
Local<Object> options; | |
if (args.Length()) { | |
options = Local<Object>::Cast(args[0]); | |
if (options->Has(NanNew("foo"))) { | |
std::cout << "has 'foo'" << std::endl; | |
Local<Value> foo_ = options->Get(NanNew("foo")); | |
if (!foo_->IsString()) { | |
std::cout << "'foo' is not a string" << std::endl; | |
NanThrowError("foo must be a string"); | |
std::cout << "we didnt throw or return???" << std::endl; | |
} | |
std::cout << "'foo' is a string" << std::endl; | |
foo = foo_->ToString(); | |
} | |
} | |
NanReturnValue(foo); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
'targets': [ | |
{ | |
'target_name': 'wut', | |
'include_dirs': [ | |
"<!(node -e \"require('nan')\")", | |
], | |
'sources': ['binding.cc'], | |
}, | |
], | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BIN := node_modules/.bin | |
GYP := $(BIN)/node-gyp | |
SRC = binding.cc | |
build: $(SRC) node_modules | |
$(GYP) rebuild | |
node_modules: package.json | |
@npm install | |
@touch $@ | |
clean: node_modules | |
$(GYP) clean | |
test: build | |
node test | |
.PHONY: clean test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "wut", | |
"dependencies": { | |
"bindings": "^1.2.1", | |
"nan": "^1.7.0", | |
"node-gyp": "^1.0.3" | |
}, | |
"main": "index", | |
"scripts": { | |
"install": "node-gyp rebuild" | |
}, | |
"gypfile": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('bindings')('wut').wut({ | |
foo: false | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment