script_bridge.rs, index.js

This commit is contained in:
Martin Kavík 2024-06-15 23:15:28 +02:00
parent a58ea4fba5
commit a299ae1082
5 changed files with 33 additions and 1 deletions

View file

@ -2,6 +2,7 @@ use std::rc::Rc;
use zoon::*;
mod platform;
mod script_bridge;
mod controls_panel;
use controls_panel::ControlsPanel;

View file

@ -0,0 +1,21 @@
use zoon::{*, println};
#[wasm_bindgen(inline_js = r#"export function strict_eval(code) { return eval?.(`"use strict"; ${code};`) }"#)]
extern "C" {
#[wasm_bindgen(catch)]
pub fn strict_eval(code: &str) -> Result<JsValue, JsValue>;
}
#[wasm_bindgen]
pub struct FW;
#[wasm_bindgen]
impl FW {
pub fn do_something() {
println!("Command result: {:#?}", strict_eval("FW.do_something_else();"));
}
pub fn do_something_else() {
println!("ELSE!");
}
}