Add further example
This commit is contained in:
parent
25972b471c
commit
d8411f8bcc
10
index.html
Normal file
10
index.html
Normal 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
11
index.js
Normal 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();
|
11
src/lib.rs
11
src/lib.rs
@ -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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user