carragom
carragom
DDeno
Created by carragom on 4/9/2024 in #help
How to go from a JS string[] to a C array of pointers
Hi, Trying to call a C function with FFI but struggling to covert a string[] to an array of pointers. Lets asume the following C function
void test_multi(int argc, const char * const *argv) {
for (int i = 0; i < argc; i++) {
puts(argv[i]);
}
}
void test_multi(int argc, const char * const *argv) {
for (int i = 0; i < argc; i++) {
puts(argv[i]);
}
}
And using some JS code I can try to call it
const enc = new TextEncoder()
const test = Deno.dlopen('./test.so'), {
test_multi: {
parameters: ['i32', 'buffer'],
result: 'void'
}
})

const params = [ 'ASD', 'ZXC' ]
test.symbols.test_multi(params.length, ??????)
const enc = new TextEncoder()
const test = Deno.dlopen('./test.so'), {
test_multi: {
parameters: ['i32', 'buffer'],
result: 'void'
}
})

const params = [ 'ASD', 'ZXC' ]
test.symbols.test_multi(params.length, ??????)
Is buffer the right type for that parameter I better us pointer?. And finally how to convert the params array to something that can be sent to the C function. Appreciate the help.
21 replies