I just gone through Calling JavaScript from C/C++ and followed their instructions. I am able to call the Js method from C++
C++
#include <iostream>
#include <string>
#include <emscripten.h>
#include <emscripten/bind.h>
EM_JS(void, call_js, (), {
jsMethod();
});
bool callJsBack()
{
call_js();
return true;
}
EMSCRIPTEN_BINDINGS(module)
{
emscripten::function("callJsBack", &callJsBack);
}
Js
<script>
var Module = {
onRuntimeInitialized: function() {
console.log('Module.callJsBack(): ' + Module.callJsBack());
}
};
function jsMethod() {
alert('I am a js method!');
}
</script>
I want to make the jsMethod() parameterized (want to pass the string from the C++ at the time of calling jsMethod()).
function jsMethod(msg) {
alert(msg);
}
I did not find any example or suggestion to achieve this requirement.