2

我正在尝试将我的旧 C++ 项目与 NodeJS 集成。我已经看过 hello word 插件教程,用于将简单的文件 c++ 文件构建到 NodeJS 中。我正在寻找一些高级示例,如果有人致力于构建从 NodeJS 到 C++ 的桥梁。我想将数据从我的 nodeJS 程序(hello.js)传递到 C++ 程序(hello.cc)

感谢帮助

4

2 回答 2

6

您需要安装node-gyp- 您可能已经安装 npm install -g node-gyp

有一个很好的例子请看一下 https://gist.githubusercontent.com/bengfarrell/4440739/raw/56e8291a31eb8f9714f8ca975c1e78a0788ae018/randomcoords.cpp

如果您无法访问,请告诉我,我会在这里过去

运行此示例 像往常一样,您需要构建它,然后创建一个 binding.gyp 文件

{
  "targets": [
    {
      "target_name": "randomcoords",
      "sources": [ "randomcoords.cc" ]
    }
  ]
}

现在在这个 c++ 插件中你可以像这样传递参数

var randCoords = require("./libs/build/Release/randomcoords.node");
var cursor = randCoords.getRandomCoords3D(600, 400, 100); // params are max values for random output
console.log('{ "x":' + cursor.x +  ', "y":' + cursor.y + ', "z":' + cursor.z + '}');

有一篇简短的文章 http://www.benfarrell.com/2013/01/03/c-and-node-js-an-unholy-combination-but-oh-so-right/

于 2016-02-16T06:45:30.920 回答
4

您可以在以下位置找到使用NAN创建本机插件的示例:

于 2016-02-16T06:45:12.820 回答