mirror of
https://codeberg.org/uzu/strudel
synced 2026-09-05 06:57:35 -04:00
add minimal zig wasm testing ground
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
# zig testing ground
|
||||
|
||||
<https://dev.to/sleibrock/webassembly-with-zig-part-1-4onm>
|
||||
|
||||
```sh
|
||||
# (re)compile add.zig
|
||||
zig build-lib add.zig -target wasm32-freestanding -dynamic -rdynamic
|
||||
# run server
|
||||
npx http-server -o
|
||||
```
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
export fn add(a: i32, b: i32) i32 {
|
||||
return a + b;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ZIG / WASM Demo</title>
|
||||
</head>
|
||||
<body>
|
||||
<h3>check the console</h3>
|
||||
</body>
|
||||
<script src="./main.js"></script>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
async function run() {
|
||||
let res = await fetch('./add.wasm');
|
||||
res = await res.arrayBuffer();
|
||||
res = await WebAssembly.instantiate(res, {
|
||||
env: {},
|
||||
});
|
||||
const { add } = res.instance.exports;
|
||||
console.log(add(3, 5));
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user