From d8411f8bcc68d858cd7efdbdcc1e9e8b08128440 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 19 Nov 2023 01:45:09 -0800 Subject: [PATCH] Add further example --- index.html | 10 ++++++++++ index.js | 11 +++++++++++ src/lib.rs | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 index.html create mode 100644 index.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..8610584 --- /dev/null +++ b/index.html @@ -0,0 +1,10 @@ + + + + + Gamarjoba, munde! + + + + + diff --git a/index.js b/index.js new file mode 100644 index 0000000..24fd012 --- /dev/null +++ b/index.js @@ -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(); diff --git a/src/lib.rs b/src/lib.rs index 1ab74d9..d1ebca2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 +}