node-bindings
地址:https://github.com/TooTallNate/node-bindings
用来帮助你加载你自己的模块的帮助模块
这是为Node.js插件模块的作者提供的辅助模块。它基本上是查找你编写的插件模块中.node文件的“瑞士军刀”。
在Node的插件历史过程中,插件最终会在各种不同的位置进行编译,具体取决于使用的构建工具和Node版本。更糟糕的是,现在gyp构建工具可以生成Release或Debug构建,每个构建都构建在不同的位置。
此模块检查将在其中构建本机插件的 所有 可能位置,并返回 第一个 成功加载的位置。
安装
npm install bindings
范例
require()
为当前节点版本,平台和体系结构提供正确的绑定文件非常简单:
var bindings = require('bindings')('binding.node')
// Use your bindings defined in your C files
bindings.your_c_function()
漂亮的错误输出
当无法加载.node
文件时,node-bindings
会抛出一个错误,并显示一条很好的错误消息,告诉您确切的尝试内容。您还可以检查err.tries
属性。
Error: Could not load the bindings file. Tried:
→ /Users/nrajlich/ref/build/binding.node
→ /Users/nrajlich/ref/build/Debug/binding.node
→ /Users/nrajlich/ref/build/Release/binding.node
→ /Users/nrajlich/ref/out/Debug/binding.node
→ /Users/nrajlich/ref/Debug/binding.node
→ /Users/nrajlich/ref/out/Release/binding.node
→ /Users/nrajlich/ref/Release/binding.node
→ /Users/nrajlich/ref/build/default/binding.node
→ /Users/nrajlich/ref/compiled/0.8.2/darwin/x64/binding.node
at bindings (/Users/nrajlich/ref/node_modules/bindings/bindings.js:84:13)
at Object.<anonymous> (/Users/nrajlich/ref/lib/ref.js:5:47)
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)
...
协议
(The MIT License)
Copyright (c) 2012 Nathan Rajlich nathan@tootallnate.net
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.