node-ffi

Using unsigned char buffer with node-ffi

£可爱£侵袭症+ 提交于 2019-12-11 07:39:55
问题 I'm having trouble using a buffer with node-ffi to call the following library function: int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size) { ... } http://www.intra2net.com/en/developer/libftdi/documentation/group__libftdi.html#ga72d87e30015c98bd0be22e7c8c873345 Which I have seen used by passing a 'unsigned char buf[size]' to as the buf argument.. So with ffi I try this: ffi = require 'ffi' ref = require 'ref' ftdiContext = ref.types.void ftdiContextPtr = ref.refType

Why EnumPrintersA and EnumPrintersW request the same amount of memory?

心不动则不痛 提交于 2019-12-10 21:06:10
问题 I call EnumPrintersA / EnumPrintersW functions using node-ffi to get list of local printers accessible from my PC. You should create the buffer which will be filled with information by EnumPrinters function. But you do not know the required size of the buffer. In this case you need to execute EnumPrintersA / EnumPrintersW twice. During the first call this function calculates the amount of memory for information about printers, during the second call this function fills the buffer with

using SendInput in Node-FFI

懵懂的女人 提交于 2019-12-08 12:31:08
问题 I wanted to use the SendInput function from the windows Api in nodejs, using the FFI package. My knowledge of C is limited so I can't really figure out what problem I have, I'm basically trying to Virtually press a key on the keyboard. That's the code I have: var ffi = require('ffi'); var ref = require ('ref'); var struct = require ('ref-struct'); var keyboardInput = struct({ 'type': 'int', 'wVK': 'int', 'wScan': 'int', 'dwFlags': 'int', 'time': 'int', 'dwExtraInfo': 'int64' }); var

Is it safe to pass js callback to a ffi function which calls it in another thread?

爱⌒轻易说出口 提交于 2019-12-05 23:33:19
问题 Say I have a C function which takes a callback and invokes it on another thread: void call_in_new_thread(void (*callback)()) { // spawn a new thread and call `callback` in it ... } Now I want to call this function from javascript via Node-FFI, passing a javascript function to it: var callbackType = 'pointer' var lib = ffi.Library('mylib', { 'call_in_new_thread': [ 'void', [ callbackType ] ], }) var callback = ffi.Callback('void', [ 'void' ], function() { // which thread I'm in now? console

Is it safe to pass js callback to a ffi function which calls it in another thread?

删除回忆录丶 提交于 2019-12-04 05:13:36
Say I have a C function which takes a callback and invokes it on another thread: void call_in_new_thread(void (*callback)()) { // spawn a new thread and call `callback` in it ... } Now I want to call this function from javascript via Node-FFI, passing a javascript function to it: var callbackType = 'pointer' var lib = ffi.Library('mylib', { 'call_in_new_thread': [ 'void', [ callbackType ] ], }) var callback = ffi.Callback('void', [ 'void' ], function() { // which thread I'm in now? console.log("hello!") }) lib.call_in_new_thread(callback) My questions: Is it valid? Is it thread safe? Which

How to return string value from a Rust FFI function in NodeJS?

牧云@^-^@ 提交于 2019-12-02 06:12:37
问题 I want to generate 6 random numbers, push them onto a vector, then use rustc_serialize to encode that vector as a JSON string to be consumed by NodeJS. extern crate rand; extern crate rustc_serialize; use rand::{OsRng, Rng}; use rustc_serialize::json::{self, Json, ToJson}; #[no_mangle] pub extern "C" fn generate() -> String { let choices: [u8; 6] = [1, 2, 3, 4, 5, 6]; let mut rand_vec: Vec<u8> = Vec::new(); let mut rng = match OsRng::new() { Ok(t) => t, Err(e) => panic!("Failed to create

How to return string value from a Rust FFI function in NodeJS?

穿精又带淫゛_ 提交于 2019-12-01 22:59:42
I want to generate 6 random numbers, push them onto a vector, then use rustc_serialize to encode that vector as a JSON string to be consumed by NodeJS. extern crate rand; extern crate rustc_serialize; use rand::{OsRng, Rng}; use rustc_serialize::json::{self, Json, ToJson}; #[no_mangle] pub extern "C" fn generate() -> String { let choices: [u8; 6] = [1, 2, 3, 4, 5, 6]; let mut rand_vec: Vec<u8> = Vec::new(); let mut rng = match OsRng::new() { Ok(t) => t, Err(e) => panic!("Failed to create OsRng!, {}", e), }; for _ in 0..5 { rand_vec.push(*rng.choose(&choices).unwrap()); } json::encode(&rand_vec

node-ffi vs. node extension for accessing existing C++ functionality

眉间皱痕 提交于 2019-11-30 06:18:48
I've got some existing C++ code that does numerical processing within a stand-alone C++ application. I now want to use that code within a new node.js application. Researching how to access C++ code from node.js, two options come up: Write a node.js extension Use node-ffi node-ffi seems like a good option to access existing libraries , but am I right thinking if I use node-ffi I would have to write a C wrapper to make my C++ accessible? (This was the only way I could get a simple test case to work on Windows with Visual Studio). For my case where my source code is already in C++, not C, what

node-ffi vs. node extension for accessing existing C++ functionality

谁说我不能喝 提交于 2019-11-29 06:06:01
问题 I've got some existing C++ code that does numerical processing within a stand-alone C++ application. I now want to use that code within a new node.js application. Researching how to access C++ code from node.js, two options come up: Write a node.js extension Use node-ffi node-ffi seems like a good option to access existing libraries , but am I right thinking if I use node-ffi I would have to write a C wrapper to make my C++ accessible? (This was the only way I could get a simple test case to

Call C++ library from Node.js (Node addons / node-ffi)

≡放荡痞女 提交于 2019-11-27 21:35:42
I'm trying to integrate an external C++ library (I have access to the .so file as well as the header files) into my Node.js application. After a lot of research my options are reduced to: Writing a Node addon Use node-ffi From node-ffi's gitHub's definition I can't tell if it will or will not work directly on C++ libraries: node-ffi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without writing any C++ code. So the questions I have are: Does option 1) imply rewriting in some way the external C++ library?