小编cra*_*c08的帖子

WebAssembly LinkError:函数导入需要可调用

我最近开始使用WebAssembly。我在尝试使用C代码中的登录时遇到问题。我以最简单的方法重新创建了错误。我得到的错误是

Uncaught (in promise) LinkError: WebAssembly.Instance(): Import #1 module="env" function="_log" error: function import requires a callable
Run Code Online (Sandbox Code Playgroud)

错误指向此功能,特别是 WebAsembly.Instance(module, imports)

function loadWebAssembly(filename, imports = {}) {
  return fetch(filename)
    .then((response) => response.arrayBuffer())
    .then((buffer) => WebAssembly.compile(buffer))
    .then((module) => {
      imports.env = imports.env || {}
      Object.assign(imports.env, {
        memoryBase: 0,
        tableBase: 0,
        memory: new WebAssembly.Memory({
          initial: 256,
          maximum: 512,
        }),
        table: new WebAssembly.Table({
          initial: 0,
          maximum: 0,
          element: 'anyfunc',
        }),
      })
      return new WebAssembly.Instance(module, imports)
    })
}
Run Code Online (Sandbox Code Playgroud)

(我将此函数称为loadWebAssembly('/test.wasm'))

我的C代码是

#include <math.h>

double test(v) …
Run Code Online (Sandbox Code Playgroud)

javascript c webassembly

5
推荐指数
1
解决办法
3155
查看次数

标签 统计

c ×1

javascript ×1

webassembly ×1