私はemscriptenアプリケーションを持っています。私は関数定義を持つjavascriptファイルを持っています。そのファイルを文字列にロードしてからemscripten_run_script
を呼び出します。次に、私はその関数を後でインラインEM_ASM
呼び出しを使って呼び出そうとしますが、関数定義が見つからないと言います。しかしグローバルスコープにJavascript関数を追加
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();
});
、私は文字列にはJavaScriptファイル、その後は私がグローバルスコープにファイルに定義されたJavaScript関数を追加することができますどのように機能
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
を呼び出して文字列を追加することをロードする場合後で使用する?
ジャバスクリプトファイルは次のようになります。
#include <stdio.h>
#include <emscripten.h>
int main()
{
char script[] = "someFunc = function() {"
"console.log(\"hello\");"
"};";
emscripten_run_script(script);
EM_ASM({
someFunc();
});
}
はあなたのscript.js
です:私は、これはあなたが何をやったかと同等であるべき、動作しているようやったテストでは
function someFunc()
{
}
"function someFunc()"から "someFunc = function()"に変更していただきありがとうございます! – pauld