how to return float* from a function using embind

210 views
Skip to first unread message

Aaron

unread,
Sep 14, 2014, 1:52:08 AM9/14/14
to emscripte...@googlegroups.com
Dear All

      I am new to emscripten, and I have read the docs and test it, it is amazing for me.
      But I have a question, I copy the demo and add a new function to return float*, then bind it and compile it.
     All the things here are ok.

     But when I invoke the getTest() in js, I got the UnboundTypeError: Cannot call MyClass.getM due to unbound types: Pf
     How can I fix it?

     The codes:
class MyClass {
public:
    MyClass(int x, std::string y)
        : x(x)
        , y(y)
    {
test[0] = 0;
test[1] = 0;
}
void incrementX() { ++x; } int getX() const { return x; } void setX(int x_) { x = x_; } float* getTest() {return test;} static std::string getStringFromInstance(const MyClass& instance) { return instance.y; } private: int x; std::string y;
float test[2];
 }; EMSCRIPTEN_BINDINGS(my_class_example) { class_<MyClass>("MyClass") .constructor<int, std::string>() .function("incrementX", &MyClass::incrementX)
.function("getTest", &MyClass::getTest, allow_raw_pointers())
  .property("x", &MyClass::getX, &MyClass::setX) .class_function("getStringFromInstance", &MyClass::getStringFromInstance) ; }

Chad Austin

unread,
Sep 15, 2014, 3:25:33 PM9/15/14
to emscripte...@googlegroups.com
Hi Aaron!

From JavaScript's perspective, what would you like getTest to return?  A single float value?  A JavaScript array?  A proxy for the memory in the Emscripten heap with some kind of accessor methods?

The meaning of a pointer is ambiguous enough that embind doesn't even try to assume a particular interpretation.


--
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.



--
Chad Austin
Technical Director, IMVU

Reply all
Reply to author
Forward
0 new messages