Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to cast an array to an string array? #179

Open
maxmedina05 opened this issue Mar 27, 2021 · 0 comments
Open

How to cast an array to an string array? #179

maxmedina05 opened this issue Mar 27, 2021 · 0 comments

Comments

@maxmedina05
Copy link

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant