September 2018
Intermediate to advanced
328 pages
9h 10m
English
You can wrap JavaScript code inside your C/C++ file with EM_ASM() and it will execute when the compiled code is run in the browser. The following code demonstrates basic usage:
#include <emscripten.h>int main() { EM_ASM( console.log('This is some JS code.'); ); return 0;}
The JavaScript code is executed immediately and cannot be reused within the C/C++ file in which it is contained. Arguments can be passed into the JavaScript code block where they arrive as variables $0, $1, and so on. These arguments can either be of type int32_t or double. The following code snippet, taken from the Emscripten site, demonstrates how to utilize arguments in an EM_ASM() block:
EM_ASM({ console.log('I received: ' + ...Read now
Unlock full access