I tried a simple example to call a C function compiled into .wasm with JavaScript.
This is the file counter.c:
#include <emscripten.h>
int counter = 100;
EMSCRIPTEN_KEEPALIVE
int count() {
counter += 1;
return counter;
}
I compiled it using emcc counter.c -s WASM=1 -o counter.js.
My main.jsJavaScript file:
const count = Module.cwrap('count ', 'number');
console.log(count());
My index.htmlfile only loads .js files into the body, nothing more:
<script type="text/javascript" src="counter.js"></script>
<script type="text/javascript" src="main.js"></script>
The error I am getting is:
Uncaught abort("Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)") at Error
when i try to call count()in main.js. How can I wait until the runtime is ready?
source
share