Trait Runtime

Source
pub trait Runtime: Resource + Default {
    type Schedule: ScheduleLabel + Debug + Clone + Eq + Hash + Default;
    type ScriptAsset: Asset + From<String> + GetExtensions;
    type ScriptData: Component<Mutability = Mutable>;
    type CallContext: Send + Clone;
    type Value: Send + Clone;
    type RawEngine;

    // Required methods
    fn with_engine_mut<T>(
        &mut self,
        f: impl FnOnce(&mut Self::RawEngine) -> T,
    ) -> T;
    fn with_engine<T>(&self, f: impl FnOnce(&Self::RawEngine) -> T) -> T;
    fn eval(
        &self,
        script: &Self::ScriptAsset,
        entity: Entity,
    ) -> Result<Self::ScriptData, ScriptingError>;
    fn register_fn(
        &mut self,
        name: String,
        arg_types: Vec<TypeId>,
        f: impl Fn(Self::CallContext, Vec<Self::Value>) -> Result<Promise<Self::CallContext, Self::Value>, ScriptingError> + Send + Sync + 'static,
    ) -> Result<(), ScriptingError>;
    fn call_fn(
        &self,
        name: &str,
        script_data: &mut Self::ScriptData,
        entity: Entity,
        args: impl for<'a> FuncArgs<'a, Self::Value, Self>,
    ) -> Result<Self::Value, ScriptingError>;
    fn call_fn_from_value(
        &self,
        value: &Self::Value,
        context: &Self::CallContext,
        args: Vec<Self::Value>,
    ) -> Result<Self::Value, ScriptingError>;
}
Expand description

Trait that represents a scripting runtime/engine. In practice it is implemented for a scripint language interpreter and the implementor provides function implementations for calling and registering functions within the interpreter.

Required Associated Types§

Required Methods§

Source

fn with_engine_mut<T>(&mut self, f: impl FnOnce(&mut Self::RawEngine) -> T) -> T

Provides mutable reference to raw scripting engine instance. Can be used to directly interact with an interpreter to use interfaces that bevy_scriptum does not provided adapters for.

Source

fn with_engine<T>(&self, f: impl FnOnce(&Self::RawEngine) -> T) -> T

Provides immutable reference to raw scripting engine instance. Can be used to directly interact with an interpreter to use interfaces that bevy_scriptum does not provided adapters for.

Source

fn eval( &self, script: &Self::ScriptAsset, entity: Entity, ) -> Result<Self::ScriptData, ScriptingError>

Source

fn register_fn( &mut self, name: String, arg_types: Vec<TypeId>, f: impl Fn(Self::CallContext, Vec<Self::Value>) -> Result<Promise<Self::CallContext, Self::Value>, ScriptingError> + Send + Sync + 'static, ) -> Result<(), ScriptingError>

Registers a new function within the scripting engine. Provided callback function will be called when the function with provided name gets called in script.

Source

fn call_fn( &self, name: &str, script_data: &mut Self::ScriptData, entity: Entity, args: impl for<'a> FuncArgs<'a, Self::Value, Self>, ) -> Result<Self::Value, ScriptingError>

Calls a function by name defined within the runtime in the context of the entity that haas been paassed. Can return a dynamically typed value that got returned from the function within a script.

Source

fn call_fn_from_value( &self, value: &Self::Value, context: &Self::CallContext, args: Vec<Self::Value>, ) -> Result<Self::Value, ScriptingError>

Calls a function by value defined within the runtime in the context of the entity that haas been paassed. Can return a dynamically typed value that got returned from the function within a script.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§