.js 创建(由 Webassembly 和 emscripten)只工作一次
.js created (by Webassembly and emscripten) works only once
我正在为一个项目使用 Webassembly 和 emscripten,网页运行良好。在其中,我将包含信息的文本区域发送到(由 Webassembly 和 emscripten)创建的 .js,以进行处理,但是,哦,有问题了!!,当我修改文本区域中的内容并重新提交时,它只能工作一次对js来说,它什么都不做。当我重新加载页面时,它再次工作(仅一次)。
我正在使用这种方式(在 Providing stdin to an emscripten HTML program? 上找到):
我评论运行();在 emscript
的最后
// in my emscript
// shouldRunNow refers to calling main(), not run().
var shouldRunNow = true;
if (Module['noInitialRun']) {
shouldRunNow = false;
}
//run(); // << here
// {{POST_RUN_ADDITIONS}}
.
result = areaInput(); \and add areaInput in result
在我的文件中添加下面的代码来激活emscript运行()
<script>
var message;
var point = -1;
function getArea(){
message = document.getElementById('input').value.split('\n');
}
function areaInput(){
if(point >= message.length - 1){
return null;
}
point += 1;
return message[point];
}
function execEmscript(){
window.console = {
log: function(str){
document.getElementById("output").value += "\n" + str;
}
}
getArea();
run();
}
</script>
io 文本区域
<textarea id="input" cols="80" rows="30"></textarea>
<textarea id="output" cols="80" rows="30"></textarea>
和一个按钮
<button onclick="execEmscript();">run</button>
也许这些设置会有所帮助:
来自 src/settings.js:
// Whether we will run the main() function. Disable if you embed the generated
// code in your own, and will call main() yourself at the right time (which you
// can do with Module.callMain(), with an optional parameter of commandline args).
var INVOKE_RUN = 1;
// If 0, the runtime is not quit when main() completes (allowing code to
// run afterwards, for example from the browser main event loop). atexit()s
// are also not executed, and we can avoid including code for runtime shutdown,
// like flushing the stdio streams.
// Set this to 1 if you do want atexit()s or stdio streams to be flushed
// on exit.
var EXIT_RUNTIME = 0;
在您的 Emscripten 版本中,您可能默认有 EXIT_RUNTIME = 1
。该文件中的其他选项也很有趣。
所以尝试指定-s INVOKE_RUN=0 -s EXIT_RUNTIME=0
到emcc
命令(你不需要注释掉run()
)。
但是您的程序可能不希望您多次调用 main()
。这可能可以通过设置 EXPORTED_FUNCTIONS
导出一些其他 C 函数并从您的 JS 调用它来解决(不确定,但您可能首先需要调用 main()
)。
我正在为一个项目使用 Webassembly 和 emscripten,网页运行良好。在其中,我将包含信息的文本区域发送到(由 Webassembly 和 emscripten)创建的 .js,以进行处理,但是,哦,有问题了!!,当我修改文本区域中的内容并重新提交时,它只能工作一次对js来说,它什么都不做。当我重新加载页面时,它再次工作(仅一次)。
我正在使用这种方式(在 Providing stdin to an emscripten HTML program? 上找到):
我评论运行();在 emscript
的最后// in my emscript
// shouldRunNow refers to calling main(), not run().
var shouldRunNow = true;
if (Module['noInitialRun']) {
shouldRunNow = false;
}
//run(); // << here
// {{POST_RUN_ADDITIONS}}
.
result = areaInput(); \and add areaInput in result
在我的文件中添加下面的代码来激活emscript运行()
<script>
var message;
var point = -1;
function getArea(){
message = document.getElementById('input').value.split('\n');
}
function areaInput(){
if(point >= message.length - 1){
return null;
}
point += 1;
return message[point];
}
function execEmscript(){
window.console = {
log: function(str){
document.getElementById("output").value += "\n" + str;
}
}
getArea();
run();
}
</script>
io 文本区域
<textarea id="input" cols="80" rows="30"></textarea>
<textarea id="output" cols="80" rows="30"></textarea>
和一个按钮
<button onclick="execEmscript();">run</button>
也许这些设置会有所帮助:
来自 src/settings.js:
// Whether we will run the main() function. Disable if you embed the generated
// code in your own, and will call main() yourself at the right time (which you
// can do with Module.callMain(), with an optional parameter of commandline args).
var INVOKE_RUN = 1;
// If 0, the runtime is not quit when main() completes (allowing code to
// run afterwards, for example from the browser main event loop). atexit()s
// are also not executed, and we can avoid including code for runtime shutdown,
// like flushing the stdio streams.
// Set this to 1 if you do want atexit()s or stdio streams to be flushed
// on exit.
var EXIT_RUNTIME = 0;
在您的 Emscripten 版本中,您可能默认有 EXIT_RUNTIME = 1
。该文件中的其他选项也很有趣。
所以尝试指定-s INVOKE_RUN=0 -s EXIT_RUNTIME=0
到emcc
命令(你不需要注释掉run()
)。
但是您的程序可能不希望您多次调用 main()
。这可能可以通过设置 EXPORTED_FUNCTIONS
导出一些其他 C 函数并从您的 JS 调用它来解决(不确定,但您可能首先需要调用 main()
)。