node-addon-examples icon indicating copy to clipboard operation
node-addon-examples copied to clipboard

How to cast an array to an string array?

Open maxmedina05 opened this issue 3 years ago • 0 comments

I'm trying to wrap a C function that receives a char** as parameter but I can't seem to cast it properly. Do I have to iterate over the array and recreate an array on c? I was following this array buffer to native example but I'm stuck. Can someone give me a hint or point me to an example that uses strings and array?

// index.js
const addon = require('./node/addon')

addon.start(4, [
  '-in',
  'str1',
  '-out',
  'str3'
])
// wrapper.cc

Napi::Value start(const Napi::CallbackInfo &info)
{
    Napi::Env env = info.Env();

    Napi::Number bufferSize = info[0].As<Napi::Number>();
    Napi::Array buffer = info[1].As<Napi::Array>();

    // how would you make this work?
    char **stringArray= reinterpret_cast<char **>(buffer);

maxmedina05 avatar Mar 27 '21 11:03 maxmedina05