pub struct RhaiScriptEngine { /* private fields */ }Expand description
MoFA Rhai 脚本引擎
Implementations§
Source§impl RhaiScriptEngine
impl RhaiScriptEngine
Sourcepub fn new(config: ScriptEngineConfig) -> Result<RhaiScriptEngine, Error>
pub fn new(config: ScriptEngineConfig) -> Result<RhaiScriptEngine, Error>
创建新的脚本引擎
Sourcepub fn compile(
&self,
id: &str,
name: &str,
source: &str,
) -> Result<CompiledScript, Error>
pub fn compile( &self, id: &str, name: &str, source: &str, ) -> Result<CompiledScript, Error>
编译脚本
Sourcepub async fn compile_and_cache(
&self,
id: &str,
name: &str,
source: &str,
) -> Result<(), Error>
pub async fn compile_and_cache( &self, id: &str, name: &str, source: &str, ) -> Result<(), Error>
编译并缓存脚本
Sourcepub async fn execute(
&self,
source: &str,
context: &ScriptContext,
) -> Result<ScriptResult, Error>
pub async fn execute( &self, source: &str, context: &ScriptContext, ) -> Result<ScriptResult, Error>
执行脚本
Sourcepub async fn execute_compiled(
&self,
script_id: &str,
context: &ScriptContext,
) -> Result<ScriptResult, Error>
pub async fn execute_compiled( &self, script_id: &str, context: &ScriptContext, ) -> Result<ScriptResult, Error>
执行已编译的脚本
Sourcepub async fn call_function<T>(
&self,
script_id: &str,
function_name: &str,
args: Vec<Value>,
context: &ScriptContext,
) -> Result<T, Error>where
T: for<'de> Deserialize<'de>,
pub async fn call_function<T>(
&self,
script_id: &str,
function_name: &str,
args: Vec<Value>,
context: &ScriptContext,
) -> Result<T, Error>where
T: for<'de> Deserialize<'de>,
调用脚本函数
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage