I have an emscripten application. I have a javascript file that has a function definition. I load that file into a string and then call emscripten_run_script on it. Then, I try to call that function later using some inline EM_ASM call, but it says the function definition can't be found.
std::ifstream file("script.js"); // script.js has "someFunc" defined
std::string str((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
emscripten_run_script( str.c_str() );
// the below give error "someFunc not defined"
EM_ASM({
someFunc();
});
However, if I load that javascript file into a string and then append the string with the call to the function
std::ifstream file("script.js"); // script.js has "someFunc" defined
std::string str((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
auto combinedStr = str + "someFunc();";
emscripten_run_script( combinedStr.c_str() ); // works fine
How can I add a javascript function defined in a file to global scope to be used later on?
The javascript file looks like this:
function someFunc()
{
}