script_bridge.rs, index.js
This commit is contained in:
parent
a58ea4fba5
commit
a299ae1082
5 changed files with 33 additions and 1 deletions
|
@ -2,6 +2,7 @@ use std::rc::Rc;
|
|||
use zoon::*;
|
||||
|
||||
mod platform;
|
||||
mod script_bridge;
|
||||
|
||||
mod controls_panel;
|
||||
use controls_panel::ControlsPanel;
|
||||
|
|
21
frontend/src/script_bridge.rs
Normal file
21
frontend/src/script_bridge.rs
Normal 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!");
|
||||
}
|
||||
}
|
Reference in a new issue