embind

Is there a more efficient way to return arrays from C++ to javascript?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 18:15:08
问题 To pass typed array from emscripten'ed C++ to javascript I came up with this code #include <emscripten/bind.h> #include <emscripten/val.h> auto test(const emscripten::val &input) { const auto data = emscripten::convertJSArrayToNumberVector<float>(input); // copies data // generate output in some form std::vector<float> output = { 1, 2, 3 }; // make a typed array view of the output emscripten::val view{ emscripten::typed_memory_view(output.size(), output.data()) }; // create new typed array to