digitalmars.D.learn - How do I make this function from module public?
- Jack (28/38) Oct 13 2020 I'm playing with wasm, I wrote a small module where I'd like to
- Jack (1/2) Oct 13 2020
- Adam D. Ruppe (4/6) Oct 13 2020 mark it `export` as well
- Jack (3/9) Oct 14 2020 worked, thanks!
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. math.dmodule math; extern(C): int mul(int a, int b) { return a * b;}wasm.dpublic import math; extern(C): // disable D mangling void doSomething() { ... } // seems to be the required entry point void _start() {}start.html: <html> <head> <script> (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; })(); </script> </head> <body> Test page <h1 id="result"></h1> </body> </html> 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:8can I make it public using D or do I have to import the wanted module with javascript?
Oct 13 2020
I'm compiling withldc2 -mtriple=wasm32-unknow-unknow-wasm -betterC wasm.d
Oct 13 2020
On Wednesday, 14 October 2020 at 01:46:11 UTC, Jack wrote:mark it `export` as well and then be sure you are compiling in this module as well, it must be included on the ldc command line along with wasm.dextern(C): int mul(int a, int b) { return a * b;}
Oct 13 2020
On Wednesday, 14 October 2020 at 01:55:13 UTC, Adam D. Ruppe wrote:On Wednesday, 14 October 2020 at 01:46:11 UTC, Jack wrote:worked, thanks!mark it `export` as well and then be sure you are compiling in this module as well, it must be included on the ldc command line along with wasm.dextern(C): int mul(int a, int b) { return a * b;}
Oct 14 2020