Skip to main content

Object

Struct Object 

Source
pub struct Object<L> { /* private fields */ }
Expand description

A single value stored on the lua stack. Type parameter L represents a value guarding the state of the lua stack (see PushGuard).

Use this type to convert between different lua values, e.g. LuaTable <-> Indexable, etc.

Implementations§

Source§

impl<L: AsLua> Object<L>

Source

pub fn read<'l, T>(&'l self, offset: i32) -> Result<T, LuaError>
where T: LuaRead<&'l Self>,

Read a lua value from the lua stack at the given offset from self.

This is useful when returning multiple values from lua functions when referenced access is required, because reading tuples only works with values which don’t reference the original lua stack guard.

§Examples:
use tlua::{Object, StringInLua, LuaTable};

// Must use `Object<_>` here because `(StringInLua<_>, i32, LuaTable<_>)`
// will simply not compile
let object: Object<_> = lua.eval("return 'text', 420, {1, 2, 3}").unwrap();

let s: StringInLua<_> = object.read(0).unwrap();
let n: i32            = object.read(1).unwrap();
let t: LuaTable<_>    = object.read(2).unwrap();

assert_eq!(s, "text");
assert_eq!(n, 420);

let values: Vec<_> =
    t.iter::<i32, i32>().map(Result::unwrap).map(|(k, v)| v).collect();
assert_eq!(values, [1, 2, 3]);
Source

pub fn guard(&self) -> &L

Source

pub fn into_guard(self) -> L

Source

pub fn index(&self) -> AbsoluteIndex

Source

pub unsafe fn try_downcast<T>(self) -> Result<T, Self>
where T: LuaRead<L>,

Try converting to a value implementing LuaRead.

§Safety

In some cases this function will result in a drop of self.guard which is invalid in case self.index is not the top of the lua stack.

Trait Implementations§

Source§

impl<L> AsLua for Object<L>
where L: AsLua,

Source§

fn as_lua(&self) -> LuaState

Source§

fn try_push<T>( self, v: T, ) -> Result<PushGuard<Self>, (<T as PushInto<Self>>::Err, Self)>
where Self: Sized, T: PushInto<Self>,

Try to push v onto the lua stack. Read more
Source§

fn push<T>(self, v: T) -> PushGuard<Self>
where Self: Sized, T: PushInto<Self>, <T as PushInto<Self>>::Err: Into<Void>,

Push v onto the lua stack. Read more
Source§

fn try_push_one<T>( self, v: T, ) -> Result<PushGuard<Self>, (<T as PushInto<Self>>::Err, Self)>
where Self: Sized, T: PushOneInto<Self>,

Try to push v onto the lua stack. Read more
Source§

fn push_one<T>(self, v: T) -> PushGuard<Self>
where Self: Sized, T: PushOneInto<Self>, <T as PushInto<Self>>::Err: Into<Void>,

Push v onto the lua stack. Read more
Source§

fn push_iter<I>(self, iterator: I) -> Result<PushGuard<Self>, Self>
where Self: Sized, I: Iterator, <I as Iterator>::Item: PushInto<LuaState>, <<I as Iterator>::Item as PushInto<LuaState>>::Err: Into<Void>,

Push iterator onto the lua stack as a lua table. Read more
Source§

fn try_push_iter<I>( self, iterator: I, ) -> Result<PushGuard<Self>, (PushIterErrorOf<I>, Self)>
where Self: Sized, I: Iterator, <I as Iterator>::Item: PushInto<LuaState>,

Push iterator onto the lua stack as a lua table. Read more
Source§

fn read<T>(self) -> ReadResult<T, Self>
where Self: Sized, T: LuaRead<Self>,

Source§

fn read_at<T>(self, index: i32) -> ReadResult<T, Self>
where Self: Sized, T: LuaRead<Self>,

Source§

fn read_at_nz<T>(self, index: NonZeroI32) -> ReadResult<T, Self>
where Self: Sized, T: LuaRead<Self>,

Source§

fn pcall<F, R>(&self, f: F) -> Result<R, LuaError>
where F: FnOnce(StaticLua) -> R,

Call a rust function in protected mode. If a lua error is thrown during execution of f the function will return a LuaError. Read more
Source§

impl<L> AsRef<Object<L>> for Callable<L>
where L: AsLua,

Source§

fn as_ref(&self) -> &Object<L>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<L> AsRef<Object<L>> for Indexable<L>
where L: AsLua,

Source§

fn as_ref(&self) -> &Object<L>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<L> AsRef<Object<L>> for IndexableRW<L>
where L: AsLua,

Source§

fn as_ref(&self) -> &Object<L>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<L> AsRef<Object<L>> for LuaFunction<L>
where L: AsLua,

Source§

fn as_ref(&self) -> &Object<L>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<L> AsRef<Object<L>> for LuaTable<L>
where L: AsLua,

Source§

fn as_ref(&self) -> &Object<L>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<L: Debug> Debug for Object<L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, L> From<CDataOnStack<'a, L>> for Object<L>

Source§

fn from(ud: CDataOnStack<'a, L>) -> Self

Converts to this type from the input type.
Source§

impl<L> From<Callable<L>> for Object<L>
where L: AsLua,

Source§

fn from(o: Callable<L>) -> Self

Converts to this type from the input type.
Source§

impl<L> From<Indexable<L>> for Object<L>
where L: AsLua,

Source§

fn from(o: Indexable<L>) -> Self

Converts to this type from the input type.
Source§

impl<L> From<IndexableRW<L>> for Object<L>
where L: AsLua,

Source§

fn from(o: IndexableRW<L>) -> Self

Converts to this type from the input type.
Source§

impl<L> From<LuaFunction<L>> for Object<L>
where L: AsLua,

Source§

fn from(o: LuaFunction<L>) -> Self

Converts to this type from the input type.
Source§

impl<L> From<LuaTable<L>> for Object<L>
where L: AsLua,

Source§

fn from(o: LuaTable<L>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T, L> From<UserdataOnStack<'a, T, L>> for Object<L>

Source§

fn from(ud: UserdataOnStack<'a, T, L>) -> Self

Converts to this type from the input type.
Source§

impl<L> LuaRead<L> for Object<L>
where L: AsLua,

Source§

fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>

Reads the data from Lua at a given position.
Source§

fn n_values_expected() -> i32

Source§

fn lua_read(lua: L) -> ReadResult<Self, L>

Reads the data from Lua.
Source§

fn lua_read_at_maybe_zero_position(lua: L, index: i32) -> ReadResult<Self, L>
where L: AsLua,

Source§

impl<L, K> Push<L> for Object<K>
where L: AsLua, K: AsLua,

Source§

type Err = Void

Error that can happen when pushing a value.
Source§

fn push_to_lua(&self, lua: L) -> PushResult<L, Self>

Pushes the value on the top of the stack. Read more
Source§

fn push_no_err(&self, lua: L) -> PushGuard<L>
where <Self as Push<L>>::Err: Into<Void>,

Same as push_to_lua but can only succeed and is only available if Err implements Into<Void>.
Source§

impl<L, K> PushInto<L> for Object<K>
where L: AsLua, K: AsLua,

Source§

type Err = Void

Source§

fn push_into_lua(self, lua: L) -> PushIntoResult<L, Self>

Push the value into lua by value
Source§

fn push_into_no_err(self, lua: L) -> PushGuard<L>
where Self: Sized, <Self as PushInto<L>>::Err: Into<Void>,

Same as push_into_lua but can only succeed and is only available if Err implements Into<Void>.
Source§

impl<L> TryFrom<Object<L>> for CDataOnStack<'_, L>
where L: AsLua,

Source§

type Error = Object<L>

The type returned in the event of a conversion error.
Source§

fn try_from(o: Object<L>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L> TryFrom<Object<L>> for Callable<L>
where L: AsLua,

Source§

type Error = Object<L>

The type returned in the event of a conversion error.
Source§

fn try_from(o: Object<L>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L> TryFrom<Object<L>> for Indexable<L>
where L: AsLua,

Source§

type Error = Object<L>

The type returned in the event of a conversion error.
Source§

fn try_from(o: Object<L>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L> TryFrom<Object<L>> for IndexableRW<L>
where L: AsLua,

Source§

type Error = Object<L>

The type returned in the event of a conversion error.
Source§

fn try_from(o: Object<L>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L> TryFrom<Object<L>> for LuaFunction<L>
where L: AsLua,

Source§

type Error = Object<L>

The type returned in the event of a conversion error.
Source§

fn try_from(o: Object<L>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L> TryFrom<Object<L>> for LuaTable<L>
where L: AsLua,

Source§

type Error = Object<L>

The type returned in the event of a conversion error.
Source§

fn try_from(o: Object<L>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T, L> TryFrom<Object<L>> for UserdataOnStack<'_, T, L>
where L: AsLua, T: Any,

Source§

type Error = Object<L>

The type returned in the event of a conversion error.
Source§

fn try_from(o: Object<L>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<L> PushOne<L> for Object<L>
where L: AsLua,

Source§

impl<L> PushOneInto<L> for Object<L>
where L: AsLua,

Auto Trait Implementations§

§

impl<L> Freeze for Object<L>
where L: Freeze,

§

impl<L> RefUnwindSafe for Object<L>
where L: RefUnwindSafe,

§

impl<L> Send for Object<L>
where L: Send,

§

impl<L> Sync for Object<L>
where L: Sync,

§

impl<L> Unpin for Object<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for Object<L>
where L: UnsafeUnpin,

§

impl<L> UnwindSafe for Object<L>
where L: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.