如何将 Dart_Handle 列表转换为 C++ 数组?

How do you convert a Dart_Handle List to a C++ array?

我正在尝试将 node.js 本机抽象移植到 dart 作为本机扩展。 node.js nan 也恰好在使用 v8 命名空间,我不是很熟悉。

我遇到问题的[不完整]代码片段是这样的:

NAN_METHOD(TestFunction) {
    NanScope();

    String::Utf8Value file(args[0]->ToString());

    int i = 0;
    Local<Array> argv_ = Local<Array>::Cast(args[1]);
    int argc = argv_->Length();
    int argl = argc + 1 + 1;
    char **argv = new char*[argl];
    argv[0] = strdup(*file);
    argv[argl-1] = NULL;
    for (; i < argc; i++) {
        String::Utf8Value arg(argv_->Get(NanNew<Integer>(i))->ToString());
    argv[i+1] = strdup(*arg);

字符串和整数相当简单,但是 dart_api.h 中数组的等效函数似乎不存在,所以我有点卡住了。这是我目前所拥有的:

void TestFunction(Dart_NativeArguments args) {
    Dart_EnterScope();

    uint8_t* file;
    intptr_t f_length = 0;
    Dart_StringToUTF8(Dart_GetNativeArgument(args, 0), &file, &f_length);

    int i = 0;
    intptr_t a_length;
    Dart_Handle a_list;
    Dart_handle a_handle;

    a_list = Dart_GetNativeArgument(args, 1);
    a_handle = Dart_ListLength(list, &a_length);

v8::Array::GetDart_ListGetAt

你会想写这样的东西:

intptr_t argc = 0;
DART_CHECK_VALID(Dart_ListLength(list, &argc));
for (intptr_t i = 0; i < argc; i++) {
  Dart_Handle element = Dart_ListGetAt(list, i);
  DART_CHECK_VALID(element);

  const char* element_str = NULL;
  DART_CHECK_VALID(Dart_StringToCString(element, &element_str));

  argv[i + 1] = strdup(element_str);
}