I am working on a google chrome extension wherein I am receiving an array of integers from the extension by pp::Var shared = dict_message.Get("shared_list");
. Now I need to pass on this array to a C function, hence need to get the elements into int*
. How do I go about doing that ?
First, make sure the pp::Var
is really an array.
if (shared.is_array()) {
Then, use the interfaces provided by class pp::VarArray
.
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;
}