pub struct ScriptEngine;Expand description
The global script engine
For rust and JavaScript interop.
Implementations§
Source§impl ScriptEngine
impl ScriptEngine
Sourcepub fn load_file(path: &str)
pub fn load_file(path: &str)
Load and run script file
To load from resource, use “:/” prefix, Example: load_file(“:/entry.js”)
Sourcepub fn call_global_function(name: &str, args: &[ScriptValue]) -> ScriptValue
pub fn call_global_function(name: &str, args: &[ScriptValue]) -> ScriptValue
Call JavaScript function
See also: make_args, ScriptValue
Sourcepub fn add_global_function<R, Fun, Args>(name: &str, func: Fun)where
Fun: ScriptFunction<R, Args> + 'static,
pub fn add_global_function<R, Fun, Args>(name: &str, func: Fun)where
Fun: ScriptFunction<R, Args> + 'static,
Export Rust function to JavaScript
Sourcepub fn remove_global_function(name: &str)
pub fn remove_global_function(name: &str)
Undo export of Rust function
Sourcepub fn add_event_listener<R, Fun, Args>(
event: &str,
func: Fun,
) -> ScriptEventHandlerwhere
R: IntoScriptValue,
Fun: ScriptFunction<R, Args> + 'static,
pub fn add_event_listener<R, Fun, Args>(
event: &str,
func: Fun,
) -> ScriptEventHandlerwhere
R: IntoScriptValue,
Fun: ScriptFunction<R, Args> + 'static,
Add an event listener callback Rust function
Sourcepub fn remove_event_listener(handler: &mut ScriptEventHandler)
pub fn remove_event_listener(handler: &mut ScriptEventHandler)
Remove an event listener callback Rust function
Sourcepub fn post_event0(event: &str)
pub fn post_event0(event: &str)
Trigger an event, both JavaScript and Rust event listeners will be notified.
Sourcepub fn post_event1(event: &str, data: impl IntoScriptValue)
pub fn post_event1(event: &str, data: impl IntoScriptValue)
Trigger an event with data, both JavaScript and Rust event listeners will be notified.
Auto Trait Implementations§
impl Freeze for ScriptEngine
impl RefUnwindSafe for ScriptEngine
impl Send for ScriptEngine
impl Sync for ScriptEngine
impl Unpin for ScriptEngine
impl UnwindSafe for ScriptEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more