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();
});
, 내가 문자열로 자바 스크립트 파일 다음은 내가 전역 범위에 파일에 정의 된 자바 스크립트 함수를 추가 할 수 있습니다 어떻게 기능
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