|
4 weeks ago | |
---|---|---|
src | 4 weeks ago | |
.gitignore | 4 weeks ago | |
Cargo.toml | 4 weeks ago | |
README.md | 4 weeks ago | |
index.html | 4 weeks ago |
README.md
roll_lib
An example library to show how to set up Rust as a Webassembly module.
Building Instructions
To build the library, use the wasm-pack
cargo extension.
It can be installed with cargo install wasm-pack
.
After installing, use wasm-pack build --release --target web
to build the artifacts into the pkg
directory.
Then, you can use WASM APIs in Javascript to use the library within Javascript.
Note that you need the entire pkg/
directory available to your browser to have it function correctly.
<script type="module">
import init, { roll } from "./pkg/roll_lib.js";
init().then(() => {
console.log(roll("1d20"));
});
</script>
Since WASN files can not generally be loaded from file://
for security reasons, you can use python -m http.server
to open a quick localhost server for testing.
Features
There is one function roll(string) -> string
.
It follows the format given in the README of the caith
library.
It may return an error or "Invalid format" if something goes wrong.