Projekt

Obecné

Profil

Stáhnout (3.39 KB) Statistiky
| Větev: | Revize:
1
node-bindings
2
=============
3
### Helper module for loading your native module's `.node` file
4

    
5
This is a helper module for authors of Node.js native addon modules.
6
It is basically the "swiss army knife" of `require()`ing your native module's
7
`.node` file.
8

    
9
Throughout the course of Node's native addon history, addons have ended up being
10
compiled in a variety of different places, depending on which build tool and which
11
version of node was used. To make matters worse, now the `gyp` build tool can
12
produce either a __Release__ or __Debug__ build, each being built into different
13
locations.
14

    
15
This module checks _all_ the possible locations that a native addon would be built
16
at, and returns the first one that loads successfully.
17

    
18

    
19
Installation
20
------------
21

    
22
Install with `npm`:
23

    
24
``` bash
25
$ npm install --save bindings
26
```
27

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

    
30

    
31
Example
32
-------
33

    
34
`require()`ing the proper bindings file for the current node version, platform
35
and architecture is as simple as:
36

    
37
``` js
38
var bindings = require('bindings')('binding.node')
39

    
40
// Use your bindings defined in your C files
41
bindings.your_c_function()
42
```
43

    
44

    
45
Nice Error Output
46
-----------------
47

    
48
When the `.node` file could not be loaded, `node-bindings` throws an Error with
49
a nice error message telling you exactly what was tried. You can also check the
50
`err.tries` Array property.
51

    
52
```
53
Error: Could not load the bindings file. Tried:
54
 → /Users/nrajlich/ref/build/binding.node
55
 → /Users/nrajlich/ref/build/Debug/binding.node
56
 → /Users/nrajlich/ref/build/Release/binding.node
57
 → /Users/nrajlich/ref/out/Debug/binding.node
58
 → /Users/nrajlich/ref/Debug/binding.node
59
 → /Users/nrajlich/ref/out/Release/binding.node
60
 → /Users/nrajlich/ref/Release/binding.node
61
 → /Users/nrajlich/ref/build/default/binding.node
62
 → /Users/nrajlich/ref/compiled/0.8.2/darwin/x64/binding.node
63
    at bindings (/Users/nrajlich/ref/node_modules/bindings/bindings.js:84:13)
64
    at Object.<anonymous> (/Users/nrajlich/ref/lib/ref.js:5:47)
65
    at Module._compile (module.js:449:26)
66
    at Object.Module._extensions..js (module.js:467:10)
67
    at Module.load (module.js:356:32)
68
    at Function.Module._load (module.js:312:12)
69
    ...
70
```
71

    
72
The searching for the `.node` file will originate from the first directory in which has a `package.json` file is found.
73

    
74
License
75
-------
76

    
77
(The MIT License)
78

    
79
Copyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;
80

    
81
Permission is hereby granted, free of charge, to any person obtaining
82
a copy of this software and associated documentation files (the
83
'Software'), to deal in the Software without restriction, including
84
without limitation the rights to use, copy, modify, merge, publish,
85
distribute, sublicense, and/or sell copies of the Software, and to
86
permit persons to whom the Software is furnished to do so, subject to
87
the following conditions:
88

    
89
The above copyright notice and this permission notice shall be
90
included in all copies or substantial portions of the Software.
91

    
92
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
93
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
94
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
95
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
96
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
97
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
98
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
(2-2/4)