Compare commits

...

2 Commits

Author SHA1 Message Date
Greg Shuflin 0633ad4b9a Add justfile 2023-11-19 01:50:37 -08:00
Greg Shuflin d8411f8bcc Add further example 2023-11-19 01:45:09 -08:00
4 changed files with 44 additions and 0 deletions

10
index.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Gamarjoba, munde!</title>
<script type="module" src="./index.js"></script>
</head>
<body>
</body>
</html>

11
index.js Normal file
View File

@ -0,0 +1,11 @@
import wasmInit from "./pkg/gamarjoba.js"
const runWasm = async () => {
const rustWasm = await wasmInit("./pkg/gamarjoba_bg.wasm");
const result = rustWasm.de_iavascriptis(0, 1);
console.log("Should be undefined: ", rustWasm.add_integer_with_constant);
document.body.textContent = `Gamarjoba! result: ${result}`;
};
runWasm();

12
justfile Normal file
View File

@ -0,0 +1,12 @@
_default:
just --list
install:
cargo install wasm-pack
build:
~/.cargo/bin/wasm-pack build --target web
serve:
python -m http.server 9001

View File

@ -4,3 +4,14 @@ use wasm_bindgen::prelude::*;
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
#[wasm_bindgen]
pub fn de_iavascriptis(a: i32, b: i32) -> i32 {
add_integer_with_constant(a, b)
}
const CONSTANT: i32 = 94;
fn add_integer_with_constant(a: i32, b: i32) -> i32 {
a + b + CONSTANT
}