Hi Florian, Unfortunately, embind doesn't yet support boost.python-like call policies ( https://wiki.python.org/moin/boost.python/CallPolicy ) which would give you a more direct way to specify what you want.
Your wrapper workaround is the right way to do this for now. :) Hope that helps, Chad On Wed, Apr 2, 2014 at 2:58 AM, Florian Rival <[email protected]>wrote: > Hi, > > I have a C++ class with a member function that return a reference to an > object contained in the class. For example: > > MyClass { > > public: > OtherClass & GetObject(unsigned int i) { return objects[i]; } > > private: > std::vector<OtherClass> objects; > > } > > However, it seems that when binding the GetObject member function with > embind and calling it from Javascript, the returned object is a copy and > not a reference/pointer to the original object. > I was able to work around the problem by creating a wrapper, like this: > > OtherClass * MyClass_GetObject(MyClass & c, unsigned int i) { return > &c.GetObject(i); } > > and then using it with embind (with allow_raw_pointers()). Using this > solution, it works like a charm (the object return when calling getObject > from Javascript is a reference to the original object, so I can modify it > and the internal object contained inside MyClass is modified), but I was > wondering if there was another way of doing it, i.e directly with the > original function using the reference, without writting "wrappers" > functions to force embind to use pointers? > > In any case, many thanks for emscripten, it's just awesome! > > Best regards, > Florian > > -- > 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. > -- Chad Austin Technical Director, IMVU http://engineering.imvu.com <http://www.imvu.com/members/Chad/> http://chadaustin.me -- 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.
