C Emscripten macros

This appendix covers

  • An overview of the emscripten_run_script series of macros
  • The EM_JS Emscripten macro
  • The EM_ASM series of Emscripten macros

Emscripten provides three types of macros that can help you talk to the host and can be quite helpful when you need to do things like debug issues with your code.

Emscripten macros come in two flavors. The first type of macro is the emscripten_run_script series of macros and the other types are the EM_JS and EM_ASM series of macros.

C.1   emscripten_run_script macros

The emscripten_run_script series of macros will execute JavaScript code directly through the use of the JavaScript eval function. The eval function is a special JavaScript function that takes a string and turns it into JavaScript code. Using evals in JavaScript is generally frowned upon because it’s slower compared to alternatives but, more importantly because, if the string you pass in contains user supplied data, that data is being turned into code that can do anything and this poses a serious security risk. Another disadvantage of using the eval function is that, depending on the browser’s security settings, a browser may prevent eval from working altogether and your code may not work as expected.

C.2   EM_JS

C.2.1   No parameter values

C.2.2   Passing parameter values

C.2.3   Passing pointers as parameters

C.2.4   Returning a string pointer

C.3   EM_ASM

C.3.1   EM_ASM

C.3.2   EM_ASM_

C.3.3   Passing pointers as parameters

C.3.4   EM_ASM_INT and EM_ASM_DOUBLE

C.3.5   Returning a string pointer

sitemap