Someone has an example of how to implement a C++ function called from JS with cwrap, whose return type is a Uint8Array?
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/068d37a5-d7d8-41fb-8e9b-88f44d33d022n%40googlegroups.com.
extern "C"
{
unsigned int const* convertStringToAscii(char* text)
{
std::string str(text);
unsigned int* ptr = (unsigned int*)malloc(str.size());
for (int i = 0; i < str.size(); i++)
{
ptr[i] = int(text[i]);
}
return ptr;
}
}
convertStringToAscii = module.cwrap('convertStringToAscii', 'string', ['array'])
console.log(convertStringToAscii("test")) => return empty
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/__5mEg_IlRc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAA2GJqWwiJamY6C4r-J2fRodkBXVAwFvTMnkSVNfEYLCGm2Rcg%40mail.gmail.com.
Thanks for the answer.My code looks like this, but I get nothing on return.Am I missing something?C++extern "C"
{
unsigned int const* convertStringToAscii(char* text)
{
std::string str(text);
unsigned int* ptr = (unsigned int*)malloc(str.size());
for (int i = 0; i < str.size(); i++)
{
ptr[i] = int(text[i]);
}
return ptr;
}
}JavascriptconvertStringToAscii = module.cwrap('convertStringToAscii', 'string', ['array'])
console.log(convertStringToAscii("test")) => return empty
--El vie, 22 jul 2022 a las 2:02, J Decker (<d3c...@gmail.com>) escribió:what you might get instead is returning a pointer to some array; which is an integer, then using that integer to get a uint8array from the U8HEAP variable, using the integer as the starting offset, and whatever length you expect...all pointers to the heap in C/C++ are really just offsets...--On Thu, Jul 21, 2022 at 5:04 PM Lorenzo Portillo <bikini...@gmail.com> wrote:Someone has an example of how to implement a C++ function called from JS with cwrap, whose return type is a Uint8Array?
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/068d37a5-d7d8-41fb-8e9b-88f44d33d022n%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/__5mEg_IlRc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAA2GJqWwiJamY6C4r-J2fRodkBXVAwFvTMnkSVNfEYLCGm2Rcg%40mail.gmail.com.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAL1%2B_hFmOY%3DCJODuBG%2ByY5jsYHDyB0yL2uf-Sk%2BZXC68mGcCgg%40mail.gmail.com.