DenoDDeno
Powered by
carragomC
Denoβ€’2y agoβ€’
20 replies
carragom

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
buffer
the right type for that parameter I better us
pointer
pointer
?. And finally how to convert the
params
params
array to something that can be sent to the C function.

Appreciate the help.
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Deno.UnsafeCallback Error (bypass string from c++ to deno)
kittyKkitty / help
2y ago
How to call a JS function from Rust?
Marcus AIreliusMMarcus AIrelius / help
3y ago
Best practice for passing Array of Objects from C++ to TS using FFI
MqxMMqx / help
9mo ago