C.2. EM_JS macros

The second type of Emscripten macro available to WebAssembly modules is the EM_JS and EM_ASM series. The EM_JS macro offers a way of declaring JavaScript functions right in your C or C++ code, whereas the EM_ASM macros allow for the use of inline JavaScript.

Although the JavaScript code for all these macros is within your C or C++ code, the Emscripten compiler actually creates the necessary JavaScript functions and calls those functions behind the scenes when the module is running. For this section, you’re going to focus on the EM_JS macro; you’ll see the EM_ASM macros in the next section.

The EM_JS macro accepts four parameters:

  • The function’s return type.
  • The function’s name.
  • The arguments for the function surrounded ...

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.