pub enum ScriptTy {
Any,
Unit,
Bool,
Int,
Float,
Str,
Array(Box<ScriptTy>),
Map(Box<ScriptTy>),
Dynamic,
Struct(ScriptStruct),
}Expand description
The shape of one parameter or return value.
A host binds a typed parameter to its own type where it can (Rhai resolves a
call by argument type) and checks the argument where it cannot (Lua binds
variadically and raises on a mismatch). ScriptTy::Any accepts whatever
the script passes, and ScriptTy::Dynamic says the same of a return that
was meant to be open rather than left undeclared.
Variants are append-only; see SCRIPT_WIRE_VERSION.
Variants§
Any
Any value; no check. This is what a signature carries where nothing was declared, so an untyped return is read as a forgotten declaration.
Unit
No value (() in Rhai, nil in Lua, null in candela).
Bool
Boolean.
Int
Signed 64-bit integer.
Float
64-bit float.
Str
String.
Array(Box<ScriptTy>)
List whose elements carry the inner type.
Map(Box<ScriptTy>)
String-keyed map whose values carry the inner type.
Dynamic
Any value, declared on purpose: the result has no shape narrower than
this one, as with a parsed JSON document. Every host treats it exactly
as Any; the difference is that the author said so,
which is what tells a deliberate open return from a missing one.
Struct(ScriptStruct)
A named set of fields with declared defaults, taken as one parameter:
the shape a function’s options have. See ScriptStruct.
A parameter type only. Each host renders it in its own terms (a struct
candela declares beside the function, a map on Rhai and Lua), and the
body always receives a ScriptValue::Map holding every field.
Implementations§
Source§impl ScriptTy
impl ScriptTy
Sourcepub fn is_dynamic(&self) -> bool
pub fn is_dynamic(&self) -> bool
Sourcepub fn accepts(&self, value: &ScriptValue) -> bool
pub fn accepts(&self, value: &ScriptValue) -> bool
Whether value satisfies this type. A dynamic type
accepts anything; an Array or
Map also checks its elements.
An integer satisfies a declared float: every scripting language Lumen
hosts spells 1 and 1.0 as the same literal kind, so seek(30)
is the call an author writes. The reverse does not hold; a float where
an integer is declared would silently drop its fraction.
Sourcepub fn empty_value(&self) -> ScriptValue
pub fn empty_value(&self) -> ScriptValue
The value a field of this type starts with when its struct declares
none: 0, 0.0, false, "", an empty list or map, a nested
struct’s own defaults, and unit for the open types. These are the
values candela gives an undeclared field, so every host agrees.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ScriptTy
impl<'de> Deserialize<'de> for ScriptTy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for ScriptTy
A type written the way candela writes it: int, float, bool,
string, null, any, T[] for an array, {string: T} for a map, and
a struct by its name. A struct name does not parse back: its fields are not
in the spelling.
impl Display for ScriptTy
A type written the way candela writes it: int, float, bool,
string, null, any, T[] for an array, {string: T} for a map, and
a struct by its name. A struct name does not parse back: its fields are not
in the spelling.
This is the spelling a declaration uses wherever a signature is written as
text rather than built in Rust, so a function described in a data file
reads the same as one a candela script declares. ScriptTy::Any and
ScriptTy::Dynamic both write as any, and any reads back as
ScriptTy::Dynamic: a type someone wrote down is a declared one.