-1
A
回答
4
的node-ffi
文档状态:
node-ffi
是Node.js的插件加载并使用纯JavaScript调用动态库。它可以用来在不编写任何C++代码的情况下创建与本地库的绑定。
您只需访问node-ffi
中所述的库并在其他地方传递结果。在他们的来源中,他们有一个例子。假设他们是在同一目录下:
文件factorial.c
:
#include <stdint.h>
uint64_t factorial(int max) {
int i = max;
uint64_t result = 1;
while (i >= 2) {
result *= i--;
}
return result;
}
文件factorial.js
:
//load the ffi module
var ffi = require('ffi');
//include the function
var libfactorial = ffi.Library('./libfactorial', {
'factorial': [ 'uint64', [ 'int' ] ]
});
if (process.argv.length < 3) {
console.log('Arguments: ' + process.argv[0] + ' ' + process.argv[1] + ' <max>');
process.exit();
};
//usage of the function
var output = libfactorial.factorial(parseInt(process.argv[2]));
console.log('Your output: ' + output);
使用的模块,C文件被加载这样的:
var libfactorial = ffi.Library('./libfactorial', {
'factorial': [ 'uint64', [ 'int' ] ]
});
然后像这样访问:
//process.argv are the command line arguments
var argument = parseInt(process.argv[2]);
var output = libfactorial.factorial(argument);
相关问题
- 1. 接口与接口
- 2. java中的接口接口
- 3. 4个接口的接口?
- 4. PHP接口接受接口参数?
- 5. 接口转换:接口{}是float64不是[]接口{} PubNub
- 6. 实体框架中的接口(接口中的接口)
- 7. C#接口 - 仅实现其他接口中的接口
- 8. 接口
- 9. 接口
- 10. 接口
- 11. 焊接@Inject接口
- 12. C++/CLI接口类与接口结构
- 13. Java - 接口,实例化一个接口?
- 14. 添加导出接口,通用接口
- 15. 两个类似接口的接口
- 16. C# - 接口 - 帮助在接口
- 17. 实现与接口集合的接口
- 18. 在接口中实现接口属性?
- 19. Qt接口:undefined接口错误
- 20. 接口扩展接口属性
- 21. 结合端口bram接口
- 22. 组织接口
- 23. vb.net:在接口
- 24. SPI接口linux
- 25. 接口数量
- 26. beanstalkd接口/ GUI
- 27. IComparable接口
- 28. DTO和接口
- 29. 接口错误
- 30. 接口引用