September 2018
Intermediate to advanced
328 pages
9h 10m
English
You need to define the JavaScript function you passed into importObj.env within the C/C++ code that utilizes it. The function signature must match what you passed in. The following example demonstrates this in greater detail. Here's the JavaScript code that interacts with the compiled C file (index.html):
// index.html <script> contentsconst env = { _logAndMultiplyTwoNums: (num1, num2) => { const result = num1 * num2; console.log(result); return result; },};loadWasm('main.wasm', { env }) .then(({ instance }) => { const result = instance.exports._callMultiply(5.5, 10); console.log(result); // 55 is logged to the console twice });
This is the contents of main.c, which is compiled to main.wasm and used within ...
Read now
Unlock full access