> 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.
This is exactly what I'm doing in my C code (no fancy "embind", but I like it that way because there's less "magic" involved"). I basically just use EM_JS() for JS functions that need to be called from C, and EMSCRIPTEN_KEEPALIVE for C functions that need to be called from JS. If I need to return complex data (anything else than just an integer return value), I call a C function from JS. For getting "data blobs" across, I pass pointers as integers to the JS side, and access the various global HEAP views from JS code, if I need to pass blob data from JS back to C, I usually pass a pointer and size to JS, and copy the data there from JS by via the HEAP views (it's also possible to call C's malloc from JS, but I haven't done that so far). On Friday, 21 February 2020 05:44:55 UTC+1, Shawn Riordan 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/1aecc9ce-c7ef-45cb-8b95-c4ff9697a5c3%40googlegroups.com.
