Add further example

This commit is contained in:
Greg Shuflin 2023-11-19 01:45:09 -08:00
parent 25972b471c
commit d8411f8bcc
3 changed files with 32 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();

View File

@ -4,3 +4,14 @@ use wasm_bindgen::prelude::*;
pub fn add(a: i32, b: i32) -> i32 { pub fn add(a: i32, b: i32) -> i32 {
a + b 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
}