pub struct Cx<'a> { /* private fields */ }Expand description
The call a PluginFn body receives: its arguments, the sink it emits
commands into, and the host it can reach.
Mirrors lumen_script::ScriptFnCx, which is what a body would receive if
the same function were registered in-process.
Implementations§
Source§impl<'a> Cx<'a>
impl<'a> Cx<'a>
Sourcepub fn new(
args: &'a [ScriptValue],
out: &'a mut Vec<ScriptCommand>,
host: Host,
) -> Self
pub fn new( args: &'a [ScriptValue], out: &'a mut Vec<ScriptCommand>, host: Host, ) -> Self
Wrap the arguments of one call, the scratch its commands land in, and the host it may call back into.
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 engine applies it on the tick the call happened, even when the call goes on to fail.