WASM hello-world build (Emscripten)

This commit is contained in:
saqib mir
2026-05-21 12:51:06 +05:30
parent 81297f7ea5
commit 86ac50cb42
3 changed files with 4650 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
#include <iostream>
#include <emscripten/emscripten.h>
extern "C" {
// Exported function: add two numbers
EMSCRIPTEN_KEEPALIVE
int add(int a, int b) {
return a + b;
}
// Exported function: print hello message
EMSCRIPTEN_KEEPALIVE
void hello() {
std::cout << "Hello from C++ WASM!" << std::endl;
}
}
+49
View File
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WASM Hello World</title>
</head>
<body>
<h1>WASM Hello World</h1>
<p>Open browser console (F12) to see output.</p>
<!-- Load generated Emscripten JS -->
<script src="wasm_hello.js"></script>
<script>
// Wait until WASM runtime is ready
Module.onRuntimeInitialized = () => {
console.log("WASM Runtime Initialized");
// Call C++ hello() function
Module.ccall(
'hello', // C++ function name
null, // return type
[], // argument types
[] // arguments
);
// Call C++ add() function
const result = Module.ccall(
'add', // function name
'number', // return type
['number', 'number'], // argument types
[5, 7] // arguments
);
console.log("Result =", result);
};
</script>
</body>
</html>
+4583
View File
File diff suppressed because it is too large Load Diff