EM_JS(const char*, get_todo_item, (const char *str), {
return Asyncify.handleAsync(async() => {
const text = UTF8ToString(str);
out("text >> " + text);
let response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
response = await response.json();
var lengthBytes = lengthBytesUTF8(jstring)+1;
var stringOnWasmHeap = _malloc(lengthBytes);
stringToUTF8(jstring, stringOnWasmHeap, lengthBytes);
return stringOnWasmHeap;
});
});
int main()
{
const char* response = get_todo_item("4455454545");
std::free( response);
return 0;
}
Got compilation error : cannot initialize a parameter of type 'void *' with an lvalue of type 'const char *' std::free( response);
Also tried: std::free((char *)response)
successful compilation but memory is not freed when checking with cout. Followed documentaion from : https://emscripten.org/docs/api_reference/emscripten.h.html#c.EM_JS