C.3. EM_ASM macros

As mentioned in the previous section, the EM_JS macro offers a way of declaring JavaScript functions right in your C or C++ code. With the EM_ASM macros, you don’t declare a JavaScript function explicitly. Instead, you write inline JavaScript in your C code. With both the EM_JS and EM_ASM macros, the JavaScript code isn’t really within the C code. The Emscripten compiler actually creates the necessary JavaScript functions and calls them behind the scenes when the module is running.

There are several variations of the EM_ASM macro available:

  • EM_ASM
  • EM_ASM_
  • EM_ASM_INT
  • EM_ASM_DOUBLE

The EM_ASM and EM_ASM_ macros don’t return a value. The EM_ASM_INT macro returns an integer, and the EM_ASM_DOUBLE macro returns a double. ...

Get WebAssembly in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.