Hi Brion,
it works. Thanks.
For the second question, I think adding a resize before set will do. But
push_back is more convenient since it looks to me that resize always
requires a second argument as initial values which are not used.
Best regards,
Ziyuan
On Friday, April 8, 2016 at 4:13:29 PM UTC+3, Ziyuan Lin wrote:
>
> I want to create an array of structs in JavaScript via Emscripten's
> interfaces:
>
>
> // minimal.cpp:
>
> #include <emscripten/bind.h>
> #include <emscripten/val.h>
> #include <emscripten/emscripten.h>
>
> using namespace emscripten;
>
> struct Point
> {
> double x,y;
> };
>
> EMSCRIPTEN_BINDINGS(FastFisheye) {
> value_object<Point>("Point")
> .field("x", &Point::x)
> .field("y", &Point::y);
> register_vector<Point>("PointVec");
> }
>
>
> compiled with em++ -O3 -std=c++11 -Wall --bind -o minimal.em.js
> minimal.cpp, and used in
>
>
> // minimal.html
> <script type="text/javascript" src="minimal.em.js" charset="utf-8"></script>
> <script type="text/javascript">
> var pointVec = new Module.PointVec();
> </script>
>
>
> The browser will complain Uncaught TypeError: Module.PointVec is not a
> constructor. But interestingly I can actually run var pointVec = new
> Module.PointVec(); in the browser's console (Chrome's, for example), but
> I cannot set the entries. Log:
>
>
> x Uncaught TypeError: Module.PointVec is not a constructor
> > var pointVec = new Module.PointVec()
> < undefined
> > pointVec
> < PointVec {$$: Object}
> > pointVec.set(0, {'x': 0, 'y': 0})
> < true
> > pointVec.get(0)
> < undefined
>
>
> where x is for error messages, > is for inputs, and < is for outputs.
> Anything going wrong?
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.