通过javaScript土地内置的对象的指针到WebAssembly(C++)函数

发布于 2025-02-06 12:35:37 字数 424 浏览 0 评论 0原文

我在C ++中具有一个(const char*)参数。我想通过将其传递给JavaScript中创建的对象的地址,在JavaScript(通过Web Assembly)中调用此函数。这可能吗?

代码就像

// Create an object by loading from url.
const encoder = await loadModel("some_url");
const data = [1,2,3];

Module.onRuntimeInitialized = _ => {
  // Call the wasm function with a pointer to the encoder.
  Module.encode(&encoder, data);
}

我如何将编码对象的地址传递给函数?

I have a function in C++ that takes a (const char*) argument. I want to call this function in JavaScript (through Web assembly) by passing to it the address of an object created in JavaScript. Is this possible?

The code is something like

// Create an object by loading from url.
const encoder = await loadModel("some_url");
const data = [1,2,3];

Module.onRuntimeInitialized = _ => {
  // Call the wasm function with a pointer to the encoder.
  Module.encode(&encoder, data);
}

How can I take the address of the encoder object to pass to the function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海未深 2025-02-13 12:35:39

将JavaScript对象序列化为原始字符串以在编程语言之间传递是常见的。

It is common to serialize the JavaScript object to a primitive string to pass between programming languages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文