In JavaScript I have a list of "lines", each of which consists of indefinite number of "points", each of which has a form of [x, y]
. So it is a 3D ragged array. Now I need to pass it to my C++ code with the help from emscripten (embind). Here's declaration of the C++ function:
Eigen::MatrixXd f(const std::vector<std::vector<std::vector<double>>>& lines);
And I would like to get a list of lists ([[m11, m12],[m22, m22],...]
) in JavaScript after calling f
. How to write the binding code in this case (the stuff inside EMSCRIPTEN_BINDINGS
, for example)?
UPDATE: I can now pass the JavaScript array to C++. The binding part is something like
typedef std::vector<double> Point;
typedef std::vector<Point> Line;
EMSCRIPTEN_BINDINGS(module) {
register_vector<Line>("LineArray");
register_vector<Point>("Line");
register_vector<double>("Point");
emscripten::function("f_wrapper", &f_wrapper);
}
where f_wrapper
calls f
but returns vector<vector<double>>
instead of MatrixXd
. Now the problem is that I can only get an empty JavaScript object after calling f_wrapper
. The JavaScript is
var Module = require('./bind.js'); // the output of em++
var cppAllLines = new Module.LineArray();
// some initialization
var result = Module.f_wrapper(cppAllLines); // an empty "Line" object
Any ideas?