That's a good point. Bound functions should be able to take references to class types. But taking an int& should be as illegal as int*.
This part of embind could certainly use improvement. On Mon, Dec 1, 2014 at 7:48 PM, awt <[email protected]> wrote: > Just curious, if embind already supports pointers to objects which allows > us to persist changes to the input parameter, shouldn't we be able to do > the same thing for references? > > On Tuesday, December 2, 2014 2:58:44 AM UTC+8, Chad Austin wrote: >> >> Hi, >> >> Your particular function could be expressed with a const reference. That >> is: >> >> int testReference(const int& input) { >> int ret = input; >> return ret; >> } >> >> (To see why it doesn't support non-const references, ask what you would >> expect embind to do when C++ modifies an argument passed to it from >> JavaScript.) >> >> >> On Tue, Nov 25, 2014 at 12:26 AM, raytrace <[email protected]> wrote: >> >>> Hi I want to use embind to expose below function with reference as >>> parameter, and build it using dmcc --bind flag, >>> >>> int testReference( int& input) >>> { >>> int ret = input; >>> return ret; >>> } >>> >>> EMSCRIPTEN_BINDINGS(my_module) { >>> >>> function("testReference", &testReference); >>> } >>> >>> however I am facing the below errors: >>> >>> */Users/swd/Emscripten/emsdk_portable/emscripten/1.25.0/system/include/emscripten/bind.h:316:25: >>> **error: * >>> >>> * non-const lvalue reference to type 'int' cannot bind to a >>> temporary of type 'int'* >>> >>> internal::BindingType<Args>:: >>> fromWireType(args)... >>> >>> * ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* >>> >>> >>> Does Embind support functions with reference as parameter? >>> >>> >>> Thanks, >>> >>> >>> -- >>> 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. > -- 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.
