c++ - How to populate a v8 array? -
i have vector std::vector<std::string> path , copy v8 array , return function.
i have tried creating new array
v8::handle<v8::array> result; and putting values path result no luck. i've tried several variations of
return scope.close(v8::array::new(/* i've tried many things in here */)); without success.
this similar question cant seem duplicate results.
how populate v8 arrays?
this example directly embedder's guide seems close want - replace new integer objects new string objects.
// function returns new array 3 elements, x, y, , z. handle<array> newpointarray(int x, int y, int z) { // creating temporary handles use handle scope. handlescope handle_scope; // create new empty array. handle<array> array = array::new(3); // return empty result if there error creating array. if (array.isempty()) return handle<array>(); // fill out values array->set(0, integer::new(x)); array->set(1, integer::new(y)); array->set(2, integer::new(z)); // return value through close. return handle_scope.close(array); } i'd read on semantics of local , persistent handles because think have got stuck.
this line:
v8::handle<v8::array> result; doesn't create new array - creates handle can later filled in array.
Comments
Post a Comment