Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
emcc main.c -O3 -o index.js -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']"
module.exports = {
mime: {
'application/wasm': ['wasm']
#include <stdio.h>
#include <stdlib.h>
#include <emscripten/emscripten.h>
int main(int argc, char ** argv) {
printf("WebAssembly module loadedn");
return 0;
#ifdef __cplusplus
extern "C" {
int EMSCRIPTEN_KEEPALIVE myFunction(int argc, char ** argv) {
printf("MyFunction Called");
return argc * 2;
#ifdef __cplusplus
<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>WebAssembly Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<button id="myFunction">Call myFunction</button>
<!-- Include the JavaScript glue code. -->
<!-- This will load the WebAssembly module and run its main. -->
<script async src="index.js"></script>
document.getElementById('myFunction').addEventListener('click', function(ev) {
var result = Module.ccall(
'myFunction', // name of C function
'number', // return type
['number'], // argument types
[42]); // arguments
console.log('Result:', result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment