将 chrome 原生客户端中的 pp::Var 数组转换为 C 整数数组

标签 c arrays google-chrome google-chrome-extension google-nativeclient

我正在开发一个 google chrome 扩展程序,其中我通过 pp::Var shared = dict_message.Get("shared_list"); 从扩展程序中接收一个整数数组。现在我需要将这个数组传递给 C 函数,因此需要将元素放入 int*。我该怎么做?

最佳答案

首先,确保 pp::Var 确实是一个数组。

if (shared.is_array()) {

然后,使用pp::VarArray类提供的接口(interface)。

    pp::VarArray array(shared);
    int * carray = new int[array.GetLength()];
    for (uint32_t i = 0; i < array.GetLength(); ++i) {
        pp::Var oneElem(array.Get(i));
        assert(oneElem.is_number());
        carray[i] = oneElem.AsInt();
    }
    // carray is ready to use
    delete [] carray;
}

关于将 chrome 原生客户端中的 pp::Var 数组转换为 C 整数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31500102/

相关文章:

c - 为什么我的数组的前一个元素会发生变化(C 中的字符串数组)

css - Chrome 的隐藏 CSS 滚动捕捉阈值以及如何更改它

html - 与 chrome 或 mozilla 相比,Internet Explorer 11 或 IE 8 显示不同的网页布局

c - 使用 2 函数进行冒泡排序

c - 优化C中数组的结构

javascript 将循环数组的函数传递给使用 switch 语句日期方法的函数

javascript - 无法在 Google 趋势页面上运行 Tampermonkey 脚本

c - 我应该使用什么编译器作为自学编译器原理技术的案例研究

PHP打包二进制数据

javascript - 如何保护数组不被刷新