pub struct ScriptFnCx<'a> { /* private fields */ }Expand description
The call a ScriptFn body receives: its arguments, and the sink it emits
commands into.
The command scratch is a plain Vec. A host moves what the body emitted
into its own sink after the body returns, so a body that calls back into the
host cannot deadlock against a lock the call is already holding.
Implementations§
Source§impl<'a> ScriptFnCx<'a>
impl<'a> ScriptFnCx<'a>
Sourcepub fn new(args: &'a [ScriptValue], out: &'a mut Vec<ScriptCommand>) -> Self
pub fn new(args: &'a [ScriptValue], out: &'a mut Vec<ScriptCommand>) -> Self
Wrap the arguments of one call and the scratch its commands land in.
Sourcepub fn args(&self) -> &[ScriptValue]
pub fn args(&self) -> &[ScriptValue]
Every argument the script passed.
Sourcepub fn arg(&self, i: usize) -> ScriptValue
pub fn arg(&self, i: usize) -> ScriptValue
Argument i, or ScriptValue::Unit when the call passed fewer.
Sourcepub fn arg_ref(&self, i: usize) -> &ScriptValue
pub fn arg_ref(&self, i: usize) -> &ScriptValue
Argument i by reference, for a body that only reads it.
Sourcepub fn str_arg(&self, i: usize) -> String
pub fn str_arg(&self, i: usize) -> String
Argument i as a string. Non-strings take their canonical rendering; a
missing argument is the empty string.
Sourcepub fn int_arg(&self, i: usize) -> i64
pub fn int_arg(&self, i: usize) -> i64
Argument i as an integer. Floats truncate, numeric strings parse, and
anything else (including a missing argument) is 0.
Sourcepub fn float_arg(&self, i: usize) -> f64
pub fn float_arg(&self, i: usize) -> f64
Argument i as a float. Integers widen, numeric strings parse, and
anything else (including a missing argument) is 0.0.
Sourcepub fn bool_arg(&self, i: usize) -> bool
pub fn bool_arg(&self, i: usize) -> bool
Argument i as a boolean. 0 and "" are false, other numbers and
non-empty strings other than "false" are true, and a missing argument
is false.
Sourcepub fn emit(&mut self, cmd: ScriptCommand)
pub fn emit(&mut self, cmd: ScriptCommand)
Queue a command. The host forwards it to the ECS message bus on the tick the call happened.