How do I make this function from module public?

Jack jckj33 at
Wed Oct 14 01:46:11 UTC 2020

I'm playing with wasm, I wrote a small module where I'd like to 
make the function available but wasm can't find this function.


>module math;
>int mul(int a, int b) { return a *  b;}


>public import math;
>extern(C): // disable D mangling
>void doSomething() { ... } // seems to be the required entry 
>void _start() {}


     (async() => {
         const response = await fetch('wasm.wasm');
         const bytes = await response.arrayBuffer();
         const { instance } = await WebAssembly.instantiate(bytes);
         const res =  instance.exports.mul(2, 4);
         console.log('The answer is: ' + res);
         document.getElementById("result").innerHTML = "The result 
is: " + res;
     Test page
     <h1 id="result"></h1>

the exported function fails to find 'mul' function, as I can see 
from the browser's console:

>start.html:8 Uncaught (in promise) TypeError: 
>instance.exports.mul is not a >function at start.html:8

can I make it public using D or do I have to import the wanted 
module with javascript?

More information about the Digitalmars-d-learn mailing list