-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. 接口引用