#include <emscripten/bind.h>#include <string>#include <vector>
using namespace emscripten;
struct employee { std::string name; int id; int salary;};
std::vector<employee> returnVectorData () { std::vector<employee
> v; v.push_back({"A", 1, 100000}); v.push_back({"B", 2, 100000});
v.push_back({"C", 3, 100000}); return v;}
EMSCRIPTEN_BINDINGS(module) { function("returnVectorData", &returnVectorData); register_vector<employee>("vector<employee>");}
var retVector = Module.returnVectorData();var vectorSize = retVector.size();
for (var i = 0; i < vectorSize; i++) { console.log("value: ", retVector.get(i)); // access values from C++ and do something}
I am new to Webassembly. I want to return a vector of struct from C++ to javascript.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
struct two { float values[]; // length can be dynamic};
struct one { struct two[]; // length can be dynamic int someValue;};
void acceptData(one[] arr){ // again here the length is not fixed
// process the data.
}
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.