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