FishyW / engine

boring stuff nothin to see here
MIT License
0 stars 0 forks source link

JS `init_*` initializer #9

Closed FishyW closed 7 months ago

FishyW commented 7 months ago

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.

#[wasm_bindgen]
fn init_test() {log("1")}

#[wasm_bindgen]
fn init_jei2ijoi2 {log("2")}

#[wasm_bindgen]
fn init_kdw133 {log("3")}

#[wasm_bindgen]
fn init_scene_MyScene {log("4")}

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.