I think there are multiple ways to do this. Embind is one option as Shachar suggested. Another is to use a little shared buffer as you mentioned - to avoid memory allocations, you can just allocate one such singleton buffer at the beginning of the program, and keep reusing it for all calls to that function. That could be very efficient.
On Thu, Feb 20, 2020 at 8:44 PM Shawn Riordan <[email protected]> wrote: > I am new at this, so don't laugh. > > I am able to make C/C++ functions that javascript can call. When the > parameters are out only. > > Can I make them return parameters? > > Lets say I want to return a point. Two values, x and y. > In C/C++ I would make my function look like: > > void getFoo( float &x, float &y); > > and have the implementation fill in the values for those two references. > The caller could then read the values out of the variables they passed in. > > How do I do a similar thing with WebAssembly and javascript? > > At the moment, I am implementing the solution by having the WebAssembly > code call back to javascript with the answer. But that feels wrong in many > ways. > > Also, allocating a shared buffer to write to, feels wrong in this case. > Since it happens on mouse move and all those memory allocations seem > wasteful. > > What is the right way to do this? > > -- > 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]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/emscripten-discuss/73244098-e837-46e7-892e-d39346405347%40googlegroups.com > <https://groups.google.com/d/msgid/emscripten-discuss/73244098-e837-46e7-892e-d39346405347%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpR_O6F0XuG6eFWwben2S2ubsJXHt6v58b3X3VLa1qY_ag%40mail.gmail.com.
