Generating asm.js Using Emscripten
Learn how Emscripten creates WebAssembly binary to optimize the compilation.
We'll cover the following...
We’ll use Emscripten to port C/C++ programs into asm.js or the WebAssembly binary and then run them inside the JavaScript engine.
Note: Programming languages such as Lua and Python have a C/C++ runtime. With Emscripten, we can port the runtime as a WebAssembly module and execute them inside the JavaScript engine. This makes it easy to run Lua/Python code on the JavaScript engine. Thus, Emscripten and WebAssembly allow the running of native code in the JavaScript engine.
First, let’s create a sum.cpp
file:
Press + to interact
extern "C" {unsigned sum(unsigned a, unsigned b) {return a + b;}}
Consider extern
"C"
(line 1) as something like an export
mechanism. All the functions inside are available as an exported function without ...