JavaScript should call every Rust (wasm_bindgen) functions that starts with init_XXXX(). This allows the Rust scripts to have multiple entry points which will be useful for macros. At the very end, JS should call init_scene_XXXX().
Implementation
Navigate to the src/routes folder, to the +page.svelte file. You'll see the function initializeWasm(). Call the init_XXXX() initializer at the end of the initializeWasm() function. If you want to call a Rust wasm_bindgen function called hello(), inside of page.svelte, you can call wasm.hello() and it should call that Rust function. But be sure to do this after the wasm module has been initialized. Make sure to build the project directory by running task lib:build beforehand.
Requirements
To see if your function works, try adding the code below to the project/src/lib.rs file.
The order of which "1,2,3" is printed is undefined (can be anything you want) but "4" should always be printed last (since it starts with init_scene_XXXX.
JavaScript should call every Rust (
wasm_bindgen
) functions that starts withinit_XXXX()
. This allows the Rust scripts to have multiple entry points which will be useful for macros. At the very end, JS should callinit_scene_XXXX()
.Implementation
Navigate to the
src/routes
folder, to the+page.svelte
file. You'll see the functioninitializeWasm()
. Call theinit_XXXX()
initializer at the end of theinitializeWasm()
function. If you want to call a Rustwasm_bindgen
function calledhello()
, inside ofpage.svelte
, you can callwasm.hello()
and it should call that Rust function. But be sure to do this after the wasm module has been initialized. Make sure to build the project directory by runningtask lib:build
beforehand.Requirements
To see if your function works, try adding the code below to the
project/src/lib.rs
file.The order of which "1,2,3" is printed is undefined (can be anything you want) but "4" should always be printed last (since it starts with
init_scene_XXXX
.