Wasm 访问 DOM [英] Wasm access DOM

查看:39
本文介绍了Wasm 访问 DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在没有 JavaScript 的情况下获得对 DOM 和/或 WebAPI(即全屏 API)的读/写访问权限?

Is there any way to get read/write access to DOM and/or the WebAPIs(i.e. fullscreen API) without JavaScript?

我正在尝试用 C 构建一个基本应用程序(C 源代码实际上是从 GC 语言转译的结果).我正在构建的应用程序将作为桌面应用程序运行(它还不能在真正的"浏览器中运行),因此我可以在必要时调整环境(即布局引擎).

I'm trying to build a basic application in C(C source being actually the result of transpilation from a GC language). The app I'm building will run as Desktop app(it's not meant to run in "real" browsers yet) so I can tweak the environment(i.e. the layout engine) if necessary.

推荐答案

在 WebAssembly 最小可行产品中,调用和调用 WebAssembly 的唯一方法是通过导入和导出.未来,WebAssembly 可能会获得允许嵌入器直接公开 API 的能力,在浏览器嵌入中,这可能包括 DOM.

In the WebAssembly Minimal Viable Product the only way to call into and out of WebAssembly is through imports and exports. In the future, WebAssembly may gain capabilities which allow the embedder expose APIs directly, in a browser embedding this could include the DOM.

导入exports 虽然不是很复杂:从你的 C 代码的角度来看,它们看起来就像一个 extern 调用,类似于 DLLWindows 平台.您可能会使用 Emscripten 编译 C 代码,请参阅 其文档从 C/C++ 调用 JavaScript 函数" 以了解有关其工作原理的详细信息(因为这不是您要问的问题,但我猜这是下一个问题).

Imports and exports aren't very complicated though: from your C code's point of view they just look like an extern call, similar to a DLL on the Windows platform. You'd likely compile the C code using Emscripten, see its documentation "Call JavaScript functions from C/C++" for details on how this works (since this isn't the question you're asking, but I'm guessing it's the next question).

从您的问题中不清楚您是否:

It's not clear from your question if you:

  1. 想要编译 C 代码并在 WebAssembly 内部浏览器中运行它.
  2. 想要编译 C 代码并在 WebAssembly 外部浏览器中运行它.
  1. Want to compile C code and run it within WebAssembly inside a browser.
  2. Want to compile C code and run it within WebAssembly outside a browser.

或两者兼而有之.

这篇关于Wasm 访问 DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆