how do i access array within the heap?

47 views
Skip to first unread message

Evert Chin

unread,
May 16, 2013, 8:15:55 AM5/16/13
to emscripte...@googlegroups.com
I had compiled a C lib into javascript code by using Emscripten. However I ran into a problem when i try to bind it with my Javascript wrapper.

I wrote this to pass it by reference, i am able to access it via the compiled lib just fine.
 
    var str_to_heapu8 = function (str) {
        return allocate(intArrayFromString(str), 'i8', ALLOC_NORMAL);
    }

However, I have trouble retrieving it back to normal javascript string... the return value is an empty string.

    var heapu8_to_str = function (ptr, len){
        var array = new Uint8Array(len);
        var i = 0;

        while( (ptr+i) < len){
            array[i] = getValue(ptr+i, 'i8');
            i++;
        }
        
        return intArrayToString(array);
    }

How can i convert it back to javascript string?e

Alon Zakai

unread,
May 16, 2013, 2:47:25 PM5/16/13
to emscripte...@googlegroups.com
See Pointer_stringify for a utility that does that.

- Alon




--
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-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

Evert Chin

unread,
May 16, 2013, 10:47:47 PM5/16/13
to emscripte...@googlegroups.com
Thank you very much!
Been trying to figure out for almost 2 days!
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages