Skip to main content

Script

Struct Script 

Source
pub struct Script<'a> { /* private fields */ }
Available on crate feature flecs_script only.
Expand description

A Script object is not associated to an entity and will be automatically deleted when it goes out of scope. For scripts that are associated with an entity, use ScriptBuilder alongside ScriptEntityView.

§Safety

Assemblies/Templates created by the script rely upon resources in the script object, and for that reason keep the script alive until all assemblies created by the script are deleted.

Implementations§

Source§

impl<'a> Script<'a>

Source

pub fn parse( world: impl WorldProvider<'a>, name: &str, code: &str, desc: Option<ecs_script_eval_desc_t>, ) -> Option<Script<'a>>

Parses and creates new script dynamically. This operation parses a script and returns a script object upon success. To run the script, call eval().

§Arguments
  • name - Name of the script (typically a file/module name).

  • code - The script code.

§See also
  • C API: ecs_script_parse
Source

pub fn eval(&self, desc: Option<ecs_script_eval_desc_t>) -> bool

Evaluate script. This operation evaluates (runs) a parsed script.

§Returns

True if success, false if failed.

§See also
  • C API: ecs_script_eval
Source

pub fn destroy(self)

Source

pub fn run_code(world: impl WorldProvider<'a>, name: &str, code: &str) -> bool

Parse script. This parses a script and instantiates the entities in the world. This operation is the equivalent to doing: parse, eval, destroy.

§Arguments
  • name - The script name (typically the file).

  • code - The script.

§Returns

True if success, false otherwise.

§See also
  • C API: ecs_script_run
Source

pub fn run_file(world: impl WorldProvider<'a>, filename: &str) -> bool

Parse script file. This parses a script file and instantiates the entities in the world. This operation is equivalent to loading the file contents and passing it to run.

§Arguments
  • filename - The script file name.
§Returns

True if success, false if failed.

Source

pub fn ast(&mut self) -> Option<String>

Convert script AST to string. This operation converts the script abstract syntax tree to a string, which can be used to debug a script.

§Returns

Some String if success, None if failed.

§See also
  • C API: script_ast_to_buf
Source

pub unsafe fn to_expr<T: IntoEntity>( world: impl WorldProvider<'a>, id_of_value: T, value: *const T::CastType, ) -> String

Serialize value into a String. This operation serializes a value of the provided type to a string.

§Safety

The caller must ensure that value points to valid data of the type specified by id_of_value.

§See also
  • C API: ecs_ptr_to_expr
Source

pub fn get_const_var( world: impl WorldProvider<'a>, name: &str, ) -> Option<ecs_value_t>

Source

pub fn get_const_numeric<T: ConstNumeric>( world: impl WorldProvider<'a>, value: ecs_value_t, ) -> T::ConstType

Source

pub fn get_const_char( world: impl WorldProvider<'a>, value: ecs_value_t, ) -> c_char

Source

pub fn get_const_str( world: impl WorldProvider<'a>, value: ecs_value_t, ) -> String

Trait Implementations§

Source§

impl Drop for Script<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !Send for Script<'a>

§

impl<'a> !Sync for Script<'a>

§

impl<'a> Freeze for Script<'a>

§

impl<'a> RefUnwindSafe for Script<'a>

§

impl<'a> Unpin for Script<'a>

§

impl<'a> UnsafeUnpin for Script<'a>

§

impl<'a> UnwindSafe for Script<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DoesNotImpl for T

Source§

const IMPLS: bool = false

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.