Trait bevy_mod_scripting::prelude::ScriptHost
source · pub trait ScriptHost: Send + Sync + 'static + Default + Resource {
type ScriptContext: Send + Sync + 'static;
type ScriptEvent: ScriptEvent;
type ScriptAsset: CodeAsset;
type APITarget: Send + Sync + 'static;
type DocTarget: DocFragment;
// Required methods
fn load_script(
&mut self,
script: &[u8],
script_data: &ScriptData<'_>,
providers: &mut APIProviders<Self>
) -> Result<Self::ScriptContext, ScriptError>;
fn setup_script(
&mut self,
script_data: &ScriptData<'_>,
ctx: &mut Self::ScriptContext,
providers: &mut APIProviders<Self>
) -> Result<(), ScriptError>;
fn handle_events<'a>(
&self,
world_ptr: &mut World,
events: &[Self::ScriptEvent],
ctxs: impl Iterator<Item = (ScriptData<'a>, &'a mut Self::ScriptContext)>,
providers: &mut APIProviders<Self>
);
fn register_with_app_in_set(app: &mut App, set: impl FreeSystemSet);
fn register_with_app_in_base_set(app: &mut App, set: impl BaseSystemSet);
// Provided method
fn run_one_shot(
&mut self,
script: &[u8],
script_name: &str,
entity: Entity,
world: &mut World,
event: Self::ScriptEvent
) -> Result<(), ScriptError> { ... }
}
Expand description
A script host is the interface between your rust application and the scripts in some interpreted language.
Required Associated Types§
sourcetype ScriptContext: Send + Sync + 'static
type ScriptContext: Send + Sync + 'static
the type of the persistent script context, representing the execution context of the script
sourcetype ScriptEvent: ScriptEvent
type ScriptEvent: ScriptEvent
the type of events picked up by lua callbacks
sourcetype ScriptAsset: CodeAsset
type ScriptAsset: CodeAsset
the type of asset representing the script files for this host
sourcetype APITarget: Send + Sync + 'static
type APITarget: Send + Sync + 'static
the type representing the target of api providers, i.e. the script engine or the script context itself
sourcetype DocTarget: DocFragment
type DocTarget: DocFragment
the type of each doc fragment
Required Methods§
sourcefn load_script(
&mut self,
script: &[u8],
script_data: &ScriptData<'_>,
providers: &mut APIProviders<Self>
) -> Result<Self::ScriptContext, ScriptError>
fn load_script( &mut self, script: &[u8], script_data: &ScriptData<'_>, providers: &mut APIProviders<Self> ) -> Result<Self::ScriptContext, ScriptError>
Loads a script in byte array format, the script name can be used to send useful errors.
sourcefn setup_script(
&mut self,
script_data: &ScriptData<'_>,
ctx: &mut Self::ScriptContext,
providers: &mut APIProviders<Self>
) -> Result<(), ScriptError>
fn setup_script( &mut self, script_data: &ScriptData<'_>, ctx: &mut Self::ScriptContext, providers: &mut APIProviders<Self> ) -> Result<(), ScriptError>
Perform one-off initialization of scripts (happens for every new or re-loaded script)
sourcefn handle_events<'a>(
&self,
world_ptr: &mut World,
events: &[Self::ScriptEvent],
ctxs: impl Iterator<Item = (ScriptData<'a>, &'a mut Self::ScriptContext)>,
providers: &mut APIProviders<Self>
)
fn handle_events<'a>( &self, world_ptr: &mut World, events: &[Self::ScriptEvent], ctxs: impl Iterator<Item = (ScriptData<'a>, &'a mut Self::ScriptContext)>, providers: &mut APIProviders<Self> )
the main point of contact with the bevy world. Scripts are called with appropriate events in the event order
sourcefn register_with_app_in_set(app: &mut App, set: impl FreeSystemSet)
fn register_with_app_in_set(app: &mut App, set: impl FreeSystemSet)
Registers the script host with the given app, and attaches handlers to deal with spawning/removing scripts in the given System Set.
Ideally place after any game logic which can spawn/remove/modify scripts to avoid frame lag. (typically CoreSet::Post_Update
)
sourcefn register_with_app_in_base_set(app: &mut App, set: impl BaseSystemSet)
fn register_with_app_in_base_set(app: &mut App, set: impl BaseSystemSet)
Registers the script host with the given app, and attaches handlers to deal with spawning/removing scripts in the given Base System Set.
Ideally place after any game logic which can spawn/remove/modify scripts to avoid frame lag. (typically CoreSet::Post_Update
)
Provided Methods§
sourcefn run_one_shot(
&mut self,
script: &[u8],
script_name: &str,
entity: Entity,
world: &mut World,
event: Self::ScriptEvent
) -> Result<(), ScriptError>
fn run_one_shot( &mut self, script: &[u8], script_name: &str, entity: Entity, world: &mut World, event: Self::ScriptEvent ) -> Result<(), ScriptError>
Loads and runs script instantaneously without storing any script data into the world.
The script id is set to u32::MAX
.