我试图让这个简单的场景工作,但我不明白如何从内存中获取数据:
在 hello.cpp 中:
void EMSCRIPTEN_KEEPALIVE modifyDOM(const char *text, const char *id) {
printf("modify dom %s with %s\n", id, text);
EM_ASM_({
console.log($0);
console.log($1);
console.log(arguments);
const elt = document.getElementById($0);
elt.innerHTML = $1;
}, id, text);
}
在 hello.html 中:
document.querySelector('.addDom').addEventListener('click', function(){
Module.ccall('modifyDOM', null, ['string', 'string'], ['Some fun text', 'textDom']);
});
我得到的是 printf 输出正确的值(即用一些有趣的文本修改 dom textDom)但 console.log 输出数字如 6736 和 6672。
我猜那是因为在 Javascript 世界中,这些值像指针一样存储在内存中。如果是这种情况,将这些值作为字符串获取的最佳方法是什么?