Hello, I have the same question as the OP on passing parameters by reference. The answer uses Pointer_make.
I can't seem to find a Pointer_make. I see this thread is from 2011, so I was hoping someone could give me updated information. Thanks On Monday, January 10, 2011 7:45:55 PM UTC-5, Jane's Conference wrote: > > Hi everyone, > I would need a little clarification on how parameter passing and > return values work in emscriptened code. > > 1. Passing an array. > > Suppose I have a function like this (function are real examples when I > can): > > void tempo_input(tempo_t * t, float const * samples, size_t n) > > Emscripten compiles as: > > function _tempo_input($t, $samples, $n) > > I need to pass a Javascript array to the function, called > javascriptArray. From the documentation, I assume I should do: > > var javascriptArray_pointer = Pointer_make (javascriptArray); > var input_res = _tempo_input(tempo_instance, javascriptArray_pointer, > javascriptArray.length); > > Is it the right thing to do? > > 2. Receiving an array as return vale. > > Now the function is: > > static float const * tempo_output(some_parameters) > > It returns a float C array. How can I translate it into a Javascript > array? I scanned into the source, and in preamble.js, Array_copy > function seemed promising, but I don't think it's the correct answer > (btw, I was looking for Pointer_make definition in order to find its > "inverse") > > 3. Passing parameters by reference > > The C function is > > void get_output (tempo_t * t, float * samples, size_t * n) > > emscriptened, it becomes: > > function _get_output($t, $samples, $n) > > Here, the samples pointer, set inside the function, points at an array > of floats when the function returns. The size_t pointer n, similarly, > is set inside the function and points to a value when the function is > done. How can I invoke a function like this from javascript, > mantaining the pass-by-reference behaviour? > > Thank you, > Cristiano. -- 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/groups/opt_out.
