【发布时间】:2018-08-29 13:24:29
【问题描述】:
这个article 演示了如何从 C 程序访问 WebAssembly 中的 DOM:
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
unsigned int EMSCRIPTEN_KEEPALIVE IncrementClickCountOnValue()
{
// Static variable that hold how many times this function was clicked
static int clicks=0;
// Modify the DOM, through a Javascript call provided by EM_ASM_, getElementById is the DOM API used
EM_ASM_( {document.getElementById("run").value='Webassembly click count: '+$0}, ++clicks );
return 1;
}
如果您编译 (emcc dom.c -O1 -s MODULARIZE=1 -s WASM=1 -o dom.js) 并运行它 (emrun --no_browser --port 8080 .),它会按预期工作。
如果没有 C,我怎么能做同样的事情,我。 e. WebAssembly text format 中的 EM_ASM_( {document.getElementById("run").value='Webassembly click count: '+$0}, ++clicks ); 相当于什么?
【问题讨论】:
标签: dom webassembly