I have a function in C++ that takes a (const char*)
argument. I want to call this function in JavaScript (through Web assembly) by passing to it the address of an object created in JavaScript. Is this possible?
The code is something like
// Create an object by loading from url.
const encoder = await loadModel("some_url");
const data = [1,2,3];
Module.onRuntimeInitialized = _ => {
// Call the wasm function with a pointer to the encoder.
Module.encode(&encoder, data);
}
How can I take the address of the encoder object to pass to the function?
It is common to serialize the JavaScript object to a primitive string to pass between programming languages.