Skip to content

Commit 5b6316c

Browse files
committed
added node 0.12 and nan versions
1 parent f7f8fcf commit 5b6316c

File tree

14 files changed

+166
-6
lines changed

14 files changed

+166
-6
lines changed

2_function_arguments/addon.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

2_function_arguments/nan/addon.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <nan.h>
2+
3+
using namespace v8;
4+
5+
NAN_METHOD(Add) {
6+
NanScope();
7+
8+
if (args.Length() < 2) {
9+
NanThrowTypeError("Wrong number of arguments");
10+
NanReturnUndefined();
11+
}
12+
13+
if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
14+
NanThrowTypeError("Wrong arguments");
15+
NanReturnUndefined();
16+
}
17+
18+
double arg0 = args[0]->NumberValue();
19+
double arg1 = args[1]->NumberValue();
20+
Local<Number> num = Number::New(arg0 + arg1);
21+
22+
NanReturnValue(num);
23+
}
24+
25+
void Init(Handle<Object> exports) {
26+
exports->Set(NanSymbol("add"), FunctionTemplate::New(Add)->GetFunction());
27+
}
28+
29+
NODE_MODULE(addon, Init)

2_function_arguments/nan/addon.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var addon = require('bindings')('addon.node')
2+
3+
console.log('This should be eight:', addon.add(3, 5))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "addon",
5+
"sources": [ "addon.cc" ],
6+
"include_dirs": [
7+
"<!(node -e \"require('nan')\")"
8+
]
9+
}
10+
]
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "function_arguments",
3+
"version": "0.0.0",
4+
"description": "Node.js Addons Example #2",
5+
"main": "addon.js",
6+
"private": true,
7+
"dependencies": {
8+
"nan": "~0.6.0",
9+
"bindings": "~1.1.1"
10+
},
11+
"scripts": {
12+
"test": "node addon.js"
13+
},
14+
"gypfile": true
15+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define BUILDING_NODE_EXTENSION
21
#include <node.h>
32

43
using namespace v8;
@@ -16,8 +15,10 @@ Handle<Value> Add(const Arguments& args) {
1615
return scope.Close(Undefined());
1716
}
1817

19-
Local<Number> num = Number::New(args[0]->NumberValue() +
20-
args[1]->NumberValue());
18+
double arg0 = args[0]->NumberValue();
19+
double arg1 = args[1]->NumberValue();
20+
Local<Number> num = Number::New(arg0 + arg1);
21+
2122
return scope.Close(num);
2223
}
2324

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var addon = require('bindings')('addon.node')
2+
3+
console.log('This should be eight:', addon.add(3, 5))
File renamed without changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
0 info it worked if it ends with ok
2+
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'install' ]
3+
2 info using npm@1.3.15
4+
3 info using node@v0.11.9
5+
4 verbose readDependencies using package.json deps
6+
5 verbose install where, deps [ '/home/rvagg/git/node-addon-examples/2_function_arguments/node_0.10',
7+
5 verbose install [] ]
8+
6 info preinstall function_arguments@0.0.0
9+
7 verbose readDependencies using package.json deps
10+
8 silly resolved []
11+
9 info build /home/rvagg/git/node-addon-examples/2_function_arguments/node_0.10
12+
10 verbose linkStuff [ false,
13+
10 verbose linkStuff false,
14+
10 verbose linkStuff false,
15+
10 verbose linkStuff '/home/rvagg/git/node-addon-examples/2_function_arguments' ]
16+
11 info linkStuff function_arguments@0.0.0
17+
12 verbose linkBins function_arguments@0.0.0
18+
13 verbose linkMans function_arguments@0.0.0
19+
14 verbose rebuildBundles function_arguments@0.0.0
20+
15 info install function_arguments@0.0.0
21+
16 verbose unsafe-perm in lifecycle true
22+
17 info function_arguments@0.0.0 Failed to exec install script
23+
18 error function_arguments@0.0.0 install: `node-gyp rebuild`
24+
18 error Exit status 1
25+
19 error Failed at the function_arguments@0.0.0 install script.
26+
19 error This is most likely a problem with the function_arguments package,
27+
19 error not with npm itself.
28+
19 error Tell the author that this fails on your system:
29+
19 error node-gyp rebuild
30+
19 error You can get their info via:
31+
19 error npm owner ls function_arguments
32+
19 error There is likely additional logging output above.
33+
20 error System Linux 3.12.0-031200-generic
34+
21 error command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
35+
22 error cwd /home/rvagg/git/node-addon-examples/2_function_arguments/node_0.10
36+
23 error node -v v0.11.9
37+
24 error npm -v 1.3.15
38+
25 error code ELIFECYCLE
39+
26 verbose exit [ 1, true ]

2_function_arguments/package.json renamed to 2_function_arguments/node_0.10/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
"description": "Node.js Addons Example #2",
55
"main": "addon.js",
66
"private": true,
7+
"dependencies": {
8+
"bindings": "~1.1.1"
9+
},
10+
"scripts": {
11+
"test": "node addon.js"
12+
},
713
"gypfile": true
814
}

0 commit comments

Comments
 (0)