The Problem
I have been fiddeling around with wasm all day, now (import $import0 "env" "_Znaj" (param i32) (result i32)) popped up in my .wat. And it breaks my code.
The Error Message
The exact error I get is:
Uncaught (in promise) LinkError: import object field '_Znaj' is not a Function
JavaScript implementation
This is how I try And use it:
const importObject = {
env: {
__memory_base: 0,
__table_base: 0,
memory: new WebAssembly.Memory({initial: 1})
}
}
fetch('wasmPrimes.wasm').then((response) =>
response.arrayBuffer()
).then((bytes) =>
WebAssembly.instantiate(bytes, importObject)
).then((results) => {
primes = results.instance.exports._Z10wasmPrimesi(amt);
});
Pic & Pastebin
Here is a pic of my c++ code and the .wat (pls follow the link I dont have 10 rep jet)
Or heres a pastebin of the entire .wat code: https://pastebin.com/6wm7sHLG
C++ Source for the wasm Module
And heres the c++ for anyone, who didn't wanna open the pic:
int* wasmPrimes(int amt)
{
int num = 1;
int* primes = new int[amt];
if (amt > 0) primes[0] = 2;
amt --;
for (int i = 0; i < amt; i++)
{
bool prime = false;
while (!prime)
{
num++;
prime = true;
for (int j = 0; j < i+1; j++)
{
if (num%primes[j]==0)
{
prime = false;
break;
}
}
}
primes[i+1] = num;
}
return primes;
}