I am using Node-ffi to write a Node bindings for MITIE. But I got problem,
The argument of a function is char**: An array of NULL terminated C strings, like this:
int run (char** tokens)
{
try
{
std::vector<std::string> words;
for (unsigned long i = 0; tokens[i]; ++i)
words.push_back(tokens[i]);
return 1;
}
catch(...)
{
return 0;
}
}
And this is what I did use ffi:
const ffi = require('ffi');
const ArrayType = require('ref-array');
const StringArray = ArrayType('string')
const test = ffi.Library('test', {
'run': [ 'int', [StringArray] ]
});
test.run(['a', 'b']);
But I got: Segmentation fault: 11.
I uploaded the sample code to this repo.
And in this repo you also can see I have wrote a Python bindings by ctypes, It runs well.
Here is my operating environment:
- [email protected]
- [email protected]
- darwin x64 17.0.0
- MacBook Pro (13-inch, 2016, Four Thunderbolt 3 Ports)
- macOS 10.13