pub struct RhaiScriptEngine { /* private fields */ }Expand description
MoFA Rhai 脚本引擎
Implementations§
Source§impl RhaiScriptEngine
impl RhaiScriptEngine
Sourcepub fn new(config: ScriptEngineConfig) -> Result<Self>
pub fn new(config: ScriptEngineConfig) -> Result<Self>
创建新的脚本引擎
Sourcepub async fn compile_and_cache(
&self,
id: &str,
name: &str,
source: &str,
) -> Result<()>
pub async fn compile_and_cache( &self, id: &str, name: &str, source: &str, ) -> Result<()>
编译并缓存脚本
Sourcepub async fn load_from_file(&self, path: &Path) -> Result<String>
pub async fn load_from_file(&self, path: &Path) -> Result<String>
从文件加载脚本
Sourcepub async fn execute(
&self,
source: &str,
context: &ScriptContext,
) -> Result<ScriptResult>
pub async fn execute( &self, source: &str, context: &ScriptContext, ) -> Result<ScriptResult>
执行脚本
Sourcepub async fn execute_compiled(
&self,
script_id: &str,
context: &ScriptContext,
) -> Result<ScriptResult>
pub async fn execute_compiled( &self, script_id: &str, context: &ScriptContext, ) -> Result<ScriptResult>
执行已编译的脚本
Sourcepub async fn call_function<T: for<'de> Deserialize<'de>>(
&self,
script_id: &str,
function_name: &str,
args: Vec<Value>,
context: &ScriptContext,
) -> Result<T>
pub async fn call_function<T: for<'de> Deserialize<'de>>( &self, script_id: &str, function_name: &str, args: Vec<Value>, context: &ScriptContext, ) -> Result<T>
调用脚本函数
Sourcepub async fn cached_scripts(&self) -> Vec<String>
pub async fn cached_scripts(&self) -> Vec<String>
获取缓存的脚本 ID 列表
Sourcepub async fn remove_cached(&self, script_id: &str) -> bool
pub async fn remove_cached(&self, script_id: &str) -> bool
移除缓存的脚本
Sourcepub async fn clear_cache(&self)
pub async fn clear_cache(&self)
清空脚本缓存
Sourcepub fn engine_mut(&mut self) -> &mut Engine
pub fn engine_mut(&mut self) -> &mut Engine
获取可变引擎引用
Auto Trait Implementations§
impl !Freeze for RhaiScriptEngine
impl !RefUnwindSafe for RhaiScriptEngine
impl Send for RhaiScriptEngine
impl Sync for RhaiScriptEngine
impl Unpin for RhaiScriptEngine
impl UnsafeUnpin for RhaiScriptEngine
impl !UnwindSafe for RhaiScriptEngine
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