pub struct ValRef<'a> { /* private fields */ }Expand description
Value reference on the lua stack
Implementations§
Source§impl<'a> ValRef<'a>
impl<'a> ValRef<'a>
Sourcepub fn deserialize<T: Deserialize<'a>>(&'a self) -> Result<T, DesErr>
pub fn deserialize<T: Deserialize<'a>>(&'a self) -> Result<T, DesErr>
Deserialize a lua value
Source§impl<'a> ValRef<'a>
impl<'a> ValRef<'a>
pub fn state(&self) -> &'a State
pub fn is_nil(&self) -> bool
pub fn is_integer(&self) -> bool
pub fn is_table(&self) -> bool
pub fn is_function(&self) -> bool
pub fn check_safe_index(&self) -> Result<()>
pub fn to_safe_bytes(&self) -> Result<&'a [u8]>
pub fn to_safe_str(&self) -> Result<&'a str>
pub fn to_bytes(&self) -> Option<&[u8]>
pub fn to_str(&self) -> Option<&str>
pub fn to_string_lossy(&self) -> Option<Cow<'_, str>>
pub fn to_bool(&self) -> bool
pub fn to_integer(&self) -> lua_Integer
pub fn to_number(&self) -> lua_Number
pub fn to_pointer(&self) -> *const c_void
pub fn to_cstr_ptr(&self) -> *const c_char
pub fn check_type(&self, ty: Type) -> Result<()>
pub fn check_type2(&self, ty1: Type, ty2: Type) -> Result<()>
Sourcepub fn cast_into<T: FromLua<'a> + 'a>(self) -> Result<T>
pub fn cast_into<T: FromLua<'a> + 'a>(self) -> Result<T>
Cast a lua value to its rust type, wrapper of FromLua::from_lua
See FromLua
Sourcepub fn cast<T: FromLua<'a> + 'static>(&self) -> Result<T>
pub fn cast<T: FromLua<'a> + 'static>(&self) -> Result<T>
Alias to cast_into(), not take the ownship, but only convert to static-lifetime types
Sourcepub fn geti(&self, i: impl Into<lua_Integer>) -> Result<ValRef<'a>>
pub fn geti(&self, i: impl Into<lua_Integer>) -> Result<ValRef<'a>>
Get value associated to integer key, equivalent to return self[i] in lua
Sourcepub fn seti<V: ToLua>(&self, i: impl Into<lua_Integer>, v: V) -> Result<()>
pub fn seti<V: ToLua>(&self, i: impl Into<lua_Integer>, v: V) -> Result<()>
Set value with integer key, equivalent to self[i] = v in lua
Sourcepub fn len(&self) -> Result<ValRef<'a>>
pub fn len(&self) -> Result<ValRef<'a>>
Get length of the value, equivalent to return #self in lua
Sourcepub fn set<K: ToLua, V: ToLua>(&self, k: K, v: V) -> Result<()>
pub fn set<K: ToLua, V: ToLua>(&self, k: K, v: V) -> Result<()>
Set value with any key, equivalent to self[k] = v in lua
Sourcepub fn get<K: ToLua>(&self, key: K) -> Result<ValRef<'a>>
pub fn get<K: ToLua>(&self, key: K) -> Result<ValRef<'a>>
Get value associated to key, equivalent to return self[k] in lua
pub fn getopt<K: ToLua, V: FromLua<'a> + 'a>(&self, k: K) -> Result<Option<V>>
Sourcepub fn pcall<T: ToLuaMulti, R: FromLuaMulti<'a>>(&self, args: T) -> Result<R>
pub fn pcall<T: ToLuaMulti, R: FromLuaMulti<'a>>(&self, args: T) -> Result<R>
Call this value as a function
Sourcepub fn pcall_void<T: ToLuaMulti>(&self, args: T) -> Result<()>
pub fn pcall_void<T: ToLuaMulti>(&self, args: T) -> Result<()>
Invoke pcall() without return value
pub fn has_metatable(&self) -> bool
Sourcepub fn set_metatable(&self, t: Table<'_>) -> Result<()>
pub fn set_metatable(&self, t: Table<'_>) -> Result<()>
Set metatable for lua table or userdata
Sourcepub fn remove_metatable(&self)
pub fn remove_metatable(&self)
Remove metatable for lua table or userdata
Sourcepub fn call_metamethod<T: ToLuaMulti, R: FromLuaMulti<'a>>(
&self,
m: &str,
args: T,
) -> Result<R>
pub fn call_metamethod<T: ToLuaMulti, R: FromLuaMulti<'a>>( &self, m: &str, args: T, ) -> Result<R>
Call a metamethod
Sourcepub fn close_and_remove_metatable(self) -> Result<()>
pub fn close_and_remove_metatable(self) -> Result<()>
Close this value, if userdata, the subsequent access to it in lua is invalid
pub fn call_close_and_remove_metatable(&self) -> Result<()>
Sourcepub fn raw_equal(&self, other: &Self) -> bool
pub fn raw_equal(&self, other: &Self) -> bool
Tests whether two lua values are equal without metamethod triggers
Sourcepub fn raw_len(&self) -> usize
pub fn raw_len(&self) -> usize
Get length of the string/userdata/table without metamethod triggers
pub fn checked_into_value(self) -> Option<Value<'a>>
pub fn into_registry_value(self) -> Result<RegVal>
pub fn into_value(self) -> Value<'a>
Sourcepub fn check_valid(self) -> Option<Self>
pub fn check_valid(self) -> Option<Self>
Return Some(self) if type is neither Type::Invalid nor Type::None
Source§impl<'a> ValRef<'a>
impl<'a> ValRef<'a>
pub fn as_userdata(&self) -> Option<&LuaUserData<'a>>
Source§impl ValRef<'_>
impl ValRef<'_>
pub fn airth_add(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_sub(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_mul(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_div(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_rem(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_bitand(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_bitor(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_bitxor(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_shl(&self, rhs: impl ToLua) -> Result<Self>
pub fn airth_shr(&self, rhs: impl ToLua) -> Result<Self>
pub fn arith_neg(&self) -> Result<Self>
pub fn arith_not(&self) -> Result<Self>
pub fn idiv(&self, rhs: impl ToLua) -> Result<Self>
pub fn pow(&self, rhs: impl ToLua) -> Result<Self>
Trait Implementations§
Source§impl<'de> Deserializer<'de> for &'de ValRef<'_>
impl<'de> Deserializer<'de> for &'de ValRef<'_>
Source§fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Require the Deserializer to figure out how to drive the visitor based
on what data type is in the input.
When implementing Deserialize, you should avoid relying on
Deserializer::deserialize_any unless you need to be told by the
Deserializer what type is in the input. Know that relying on
Deserializer::deserialize_any means your data type will be able to
deserialize from self-describing formats only, ruling out Bincode and
many others.
Source§fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a bool value.
Source§fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting an i8 value.
Source§fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting an i16 value.
Source§fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting an i32 value.
Source§fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting an i64 value.
Source§fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a u8 value.
Source§fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a u16 value.
Source§fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a u32 value.
Source§fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a u64 value.
Source§fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a f32 value.
Source§fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a f64 value.
Source§fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a char value.
Source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer.
If the Visitor would benefit from taking ownership of String data,
indiciate this to the Deserializer by using deserialize_string
instead.
Source§fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer.
If the Visitor would not benefit from taking ownership of String
data, indicate that to the Deserializer by using deserialize_str
instead.
Source§fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer.
If the Visitor would benefit from taking ownership of Vec<u8> data,
indicate this to the Deserializer by using deserialize_byte_buf
instead.
Source§fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer.
If the Visitor would not benefit from taking ownership of Vec<u8>
data, indicate that to the Deserializer by using deserialize_bytes
instead.
Source§fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting an optional value.
This allows deserializers that encode an optional value as a nullable
value to convert the null value into None and a regular value into
Some(value).
Source§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a unit value.
Source§fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a unit struct with a
particular name.
Source§fn deserialize_newtype_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a newtype struct with a
particular name.
Source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a sequence of values.
Source§fn deserialize_tuple<V>(
self,
len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_tuple<V>(
self,
len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a sequence of values and
knows how many values there are without looking at the serialized data.
Source§fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a tuple struct with a
particular name and number of fields.
Source§fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a map of key-value pairs.
Source§fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting a struct with a particular
name and fields.
Source§fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting an enum value with a
particular name and possible variants.
Source§fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type is expecting the name of a struct
field or the discriminant of an enum variant.
Source§fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Hint that the Deserialize type needs to deserialize a value whose type
doesn’t matter because it is ignored.
Deserializers for non-self-describing formats may not support this mode.
Source§type Error = DesErr
type Error = DesErr
Source§fn deserialize_i128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
Source§fn deserialize_u128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u128<V>(
self,
visitor: V,
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
Source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize implementations should expect to
deserialize their human-readable form. Read more