Let's say i have source and header files for C code (bus-driver.c and bus-driver.h) can i call functions inside them from node.js
for example bus-driver.h
void bus_init(void);
void bus_write(char *buf);
I want to call these functions from node.js.
The nodeffi seems to be simplest way to do that. I didn't test it so it can has problems that I don't realize now.
But I would suggest to do something like that, following the tutorial. Install nodeffi:
Generate a library for your bus-driver if you don't have one, let's call it libbusdriver.
Then in your javascript do something similar to this:
var ffi = require('ffi');
var libbusdriver = ffi.Library('libbusdriver', {
'bus_init': [ 'void', [ 'void' ] ],
'bus_write': [ 'void', [ 'string' ] ],
});
libbusdriver.bus_init();
libbusdriver.bus_write("Hello");
Let me know if it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With