Enum darklua_core::process::LuaValue[][src]

pub enum LuaValue {
    False,
    Function,
    Nil,
    Number(f64),
    String(String),
    Table,
    True,
    Unknown,
}
Expand description

Represents an evaluated Expression result.

Variants

False
Function
Nil
Number(f64)

Tuple Fields of Number

0: f64
String(String)

Tuple Fields of String

0: String
Table
True
Unknown

Implementations

As defined in Lua, all values are considered true, except for false and nil. An option is returned as the LuaValue may be unknown, so it would return none.


// the values considered false
assert!(!LuaValue::False.is_truthy().unwrap());
assert!(!LuaValue::Nil.is_truthy().unwrap());

// all the others are true
assert!(LuaValue::True.is_truthy().unwrap());
assert!(LuaValue::Table.is_truthy().unwrap());
assert!(LuaValue::Number(0.0).is_truthy().unwrap());
assert!(LuaValue::String("hello".to_owned()).is_truthy().unwrap());

// unknown case
assert!(LuaValue::Unknown.is_truthy().is_none());

If the value is unknown, this will also return unknown value. In the other case, if the value is considered truthy (see is_truthy function), it will call the given function to get the mapped value.

Like the map_if_truthy method, except that instead of returning the same value when the it is falsy, it calls the default callback to obtain another value.

Attempt to convert the Lua value into an expression node.

Attempt to convert the Lua value into a number value. This will convert strings when possible and return the same value otherwise.

Attempt to convert the Lua value into a string value. This will convert numbers when possible and return the same value otherwise.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.