小生对 WebAssembly 很感兴趣, 但是初学的时候就碰壁 在 google,baidu 后仍没有找到解决的方法, 学识浅薄,也不知道问题出在哪儿。
在用 assemblyscript 写了一个简单的函数, 是算斐波那契的第 n 项
export function Fibonacci(x:i32):i32{
if(x === 1 || x === 2) {
return 1
}
return f(x - 1) + f(x - 2)
}
然后使用 asc 转到 f.wasm
asc main.ts -o f.wasm
问题就是在 fetch 这个 f.wasm 的时候,老是报错
//加载 webassembly 模块
(async () => {
let mod = await fetch("./f.wasm")
.then(res => res.arrayBuffer())
.then(src => WebAssembly.instantiate(src))
.catch(err => console.log(err))
})()
报错信息为:
CompileError: AsyncCompile: Wasm decoding failed: expected section length @+115
实在不解,难道是跟一些硬件有关系吗? 报这个错是为什么? 要怎么解决?