WASM-ready version of dicelang for browser usage.
wasm-pack build --no-typescript --target web
Place the .js
and .wasm
files in a directory (e.g. dicelang
) on the web
server. Then use a snippet like this to load and use:
<script type="module">
import init, { roll } from './dicelang/dicelang_wasm.js';
async function run() {
await init();
let {result, rolls} = roll("d20+1d4-1d6+3");
console.log("result:", result);
console.log("rolls:", rolls);
}
run();
</script>
Reference for the above: https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html