Thanks very much for the info, Chad. Would it be possible for you to amend
my gist to employ your technique??

Best,
Arve

On Tue, Sep 16, 2014 at 11:36 PM, Chad Austin <c...@imvu.com> wrote:

> If you want to write the C code such that it writes to a float*, then that
> data has to live inside the Emscripten heap.
>
> That is, JavaScript must reserve some space in the Emscripten heap (via
> _malloc, for example), and pass the pointer to the C function.
>
> Then, JavaScript can read the floats out of the array by accessing
> HEAPF32[(p>>2) + index] where p is the pointer returned by _malloc and
> index is the index into the array.
>
>
> On Tue, Sep 16, 2014 at 2:17 PM, Arve Knudsen <arve.knud...@gmail.com>
> wrote:
>
>> Hi guys
>>
>> I need to pass an array of floating point numbers from a JavaScript
>> library to a C callback, so that the latter can fill the array with data.
>> I'm using Runtime.getFuncWrapper to be able to call the C callback from
>> JavaScript.
>>
>> How do I pass an array to the C callback, so that it appears as a
>> writeable array of floats to the latter?
>>
>> I've created a gist of an Emscripten-generated HTML page, to demonstrate
>> the scenario: https://gist.github.com/aknuds1/fd6348ab32583dea8b4a. It
>> shows what I've tried so far, the problem being that the data written to
>> the array by the C function doesn't make it back to the calling JavaScript
>> function. Compile the gist into an HTML page like so:
>>
>>     emcc --js-library library.js -o tst.html tst.cpp.
>>
>> The JavaScript function is called 'initialize', while the C callback is
>> called 'callback'. Let me know if anything is unclear.
>>
>> Thanks,
>> Arve
>>
>> --
>> 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 emscripten-discuss+unsubscr...@googlegroups.com.
>> 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 emscripten-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to