创建第一个节点.js插件
Creating first node.js addon
我正在按照文档创建一个节点.js插件。 我跑了
node-gyp configure build --python C:'Python27
并收到错误
错误:生成 ENOENT
全栈:
gyp info it worked if it ends with ok
gyp info using node-gyp@1.0.3
gyp info using node@0.10.29 | win32 | x64
gyp ERR! configure error
gyp ERR! stack Error: spawn ENOENT
gyp ERR! stack at errnoException (child_process.js:1000:11)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:791:34)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:''Users''bmackey''AppData''Roaming''npm''node_modules''node-gyp''bin''node-gyp.js" "configure" "build" "--python" "C:''Python27"
gyp ERR! cwd D:'DevProjects'Node'AddOn
gyp ERR! node -v v0.10.29
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
我的 3 个必需文件都在同一个目录中:
hello.cc:
// hello.cc
#include <node.h>
//Note that all node addons must export an initialization function.
//Does this go in a .h or here or what?
void Initialize (Handle<Object> exports);
NODE_MODULE(module_name, Initialize)
using namespace v8;
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}
void init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE(addon, init)
binding.gyp:
{
"targets": [
{
"target_name": "addon",
"sources": [ "hello.cc" ]
}
]
}
您好.js:
var addon = require('./build/Release/addon');
console.log(addon.hello()); // 'world'
可选的--python
参数需要 python 的路径.exe:
node-gyp configure build --python C:'Python27'python.exe
node.js网站上的示例对我不起作用。 这家伙的例子效果更好,但最终这奏效了,对我来说更有意义:
hello.cc
#include <node.h>
using namespace v8;
Handle<Value> Method(const Arguments& args) {
HandleScope scope;
return scope.Close(String::New("here is some output"));
}
void init(Handle<Object> target) {
target->Set(String::NewSymbol("methodName"),
FunctionTemplate::New(Method)->GetFunction());
}
NODE_MODULE(myModuleName, init)
binding.gyp:
{
"targets": [
{
"target_name": "myModuleName",
"sources": [ "hello.cc" ]
}
]
}
您好.js:
var addon = require('./build/Release/myModuleName');
console.log(addon.methodName()); // prints "here is some output"
这种布局消除了一些命名歧义。
相关文章:
- Wordpress插件根据需要加载js和css
- 如何在JS Leatflet绘图插件中获取圆的坐标
- 带有jquery插件的backbone.js视图
- 使用Tabris-js,并尝试使用cordova文件和文件传输插件
- CKeditor预览插件.js,为Chrome和IE进行编辑.因为它拒绝CSS样式
- r.js评估'text'插件,尽管在'stubModules'参数
- 当我使用JS/jQuery/any插件点击图像时,我如何使背景变暗+不可点击,并放大和居中我的图像
- IE 9 BHO插件.加载外部JS文件时出现错误SCRIPT1014
- Backbone.js与jQuery的Lazy加载插件
- 借助D3.js集成Datatables插件
- JS错误导致WordPress插件无法工作
- 访问插件JS中的Wordpress PHP变量
- 我该如何为video.js制作一个插件,在HTML标题中添加和删除三角形
- React/Node应用程序中的Facebook评论插件.js仅在刷新时显示
- 引导主.js和插件.js脚本有什么用
- 在ajax页面加载内容后加载jquery插件js
- 在插件js中添加函数,而无需实际修改js文件
- 恢复插件JS
- 动态加载jQuery和插件js
- 动态加载时加载插件js文件失败