How to cast an array to an string array?

Aperta
#179 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, node.js
Ambito
backend

Direzione di ricerca

Start by comparing wrapper.cc and index.js with the linked array_buffer_to_native example, focusing on how the N-API array is passed into native code. Check whether the repository contains another string-array example. Done means providing or documenting a working example for the shown char** use case.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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);
Lingua principale
C++
Stelle
2.6k
Fork
602
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/node-addon-examples

Tutte le issue di nodejs/node-addon-examples

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.