Struct bevy_scriptum::ScriptingRuntime
source · pub struct ScriptingRuntime { /* private fields */ }
Implementations§
source§impl ScriptingRuntime
impl ScriptingRuntime
sourcepub fn engine_mut(&mut self) -> &mut Engine
pub fn engine_mut(&mut self) -> &mut Engine
Get a mutable reference to the internal rhai::Engine.
Examples found in repository?
examples/custom_type.rs (line 25)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn startup(
mut commands: Commands,
mut scripting_runtime: ResMut<ScriptingRuntime>,
assets_server: Res<AssetServer>,
) {
let engine = scripting_runtime.engine_mut();
engine
.register_type_with_name::<MyType>("MyType")
// Register a method on MyType
.register_fn("my_method", |my_type_instance: &mut MyType| {
my_type_instance.my_field
})
// Register a "constructor" for MyType
.register_fn("new_my_type", || MyType { my_field: 42 });
commands.spawn(Script::new(assets_server.load("examples/custom_type.rhai")));
}
sourcepub fn call_fn(
&mut self,
function_name: &str,
script_data: &mut ScriptData,
entity: Entity,
args: impl FuncArgs
) -> Result<(), ScriptingError>
pub fn call_fn( &mut self, function_name: &str, script_data: &mut ScriptData, entity: Entity, args: impl FuncArgs ) -> Result<(), ScriptingError>
Call a function that is available in the scope of the script.
Trait Implementations§
source§impl Default for ScriptingRuntime
impl Default for ScriptingRuntime
source§fn default() -> ScriptingRuntime
fn default() -> ScriptingRuntime
Returns the “default value” for a type. Read more
impl Resource for ScriptingRuntime
Auto Trait Implementations§
impl Freeze for ScriptingRuntime
impl !RefUnwindSafe for ScriptingRuntime
impl Send for ScriptingRuntime
impl Sync for ScriptingRuntime
impl Unpin for ScriptingRuntime
impl !UnwindSafe for ScriptingRuntime
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates
Self
using data from the given World
.