nodejs / node-addon-examples

Node.js C++ addon examples from http://nodejs.org/docs/latest/api/addons.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to cast an array to an string array?

maxmedina05 opened this issue · 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);