You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
899 B

  1. # Prototype
  2. Link for compiling code with Embind → https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html
  3. **Command for compiling code with Embind:**
  4. ```
  5. emcc -lembind -o test.js test.cpp -s NO_EXIT_RUNTIME=1 -s "EXPORTED_RUNTIME_METHODS=['ccall']"
  6. ```
  7. - **EMSCRIPTEN_BINDINGS** macro is used to bind the C++ function to make it callable from JavaScript [Code](https://git.pranger.xyz/varnicas/testingwasm/src/branch/main/C++/test.cpp#L12-L15)
  8. - Emscripten compiles the C++ code to WebAssembly, generating a **.wasm** file and **JavaScript** glue code that loads the WebAssembly module and sets up the bindings
  9. - When the HTML page is loaded, **test.js** is executed, loading the WebAssembly module , Emscripten's Module object is
  10. created, exposing the C++ functions (like myFunction) to JavaScript
  11. - Example of using **Module**: var result = Module.myFunction(input)