Trait tlua::AsLua

source ·
pub trait AsLua {
    // Required method
    fn as_lua(&self) -> *mut lua_State;

    // Provided methods
    fn try_push<T>(
        self,
        v: T
    ) -> Result<PushGuard<Self>, (<T as PushInto<Self>>::Err, Self)>
       where Self: Sized,
             T: PushInto<Self> { ... }
    fn push<T>(self, v: T) -> PushGuard<Self>
       where Self: Sized,
             T: PushInto<Self>,
             <T as PushInto<Self>>::Err: Into<Void> { ... }
    fn try_push_one<T>(
        self,
        v: T
    ) -> Result<PushGuard<Self>, (<T as PushInto<Self>>::Err, Self)>
       where Self: Sized,
             T: PushOneInto<Self> { ... }
    fn push_one<T>(self, v: T) -> PushGuard<Self>
       where Self: Sized,
             T: PushOneInto<Self>,
             <T as PushInto<Self>>::Err: Into<Void> { ... }
    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> { ... }
    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> { ... }
    fn read<T>(self) -> ReadResult<T, Self>
       where Self: Sized,
             T: LuaRead<Self> { ... }
    fn read_at<T>(self, index: i32) -> ReadResult<T, Self>
       where Self: Sized,
             T: LuaRead<Self> { ... }
    fn read_at_nz<T>(self, index: NonZeroI32) -> ReadResult<T, Self>
       where Self: Sized,
             T: LuaRead<Self> { ... }
    fn pcall<F, R>(&self, f: F) -> Result<R, LuaError>
       where F: FnOnce(StaticLua) -> R { ... }
}
Expand description

Trait for objects that have access to a Lua context.

Required Methods§

Provided Methods§

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.

In case of success returns a PushGuard which captures self by value and stores the amount of values pushed onto the stack.

In case of failure returns a tuple with 2 elements:

  • an error, which occured during the attempt to push
  • self
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.

This method is only available if T::Err implements Into<Void>, which means that no error can happen during the attempt to push.

Returns a PushGuard which captures self by value and stores the amount of values pushed onto the stack.

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.

This method is only available if T implements PushOneInto, which means that it pushes a single value onto the stack.

Returns a PushGuard which captures self by value and stores the amount of values pushed onto the stack (ideally this will be 1, but it is the responsibility of the impelemntor to make sure it is so).

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.

This method is only available if

  • T implements PushOneInto, which means that it pushes a single value onto the stack
  • T::Err implements Into<Void>, which means that no error can happen during the attempt to push

Returns a PushGuard which captures self by value and stores the amount of values pushed onto the stack (ideally this will be 1, but it is the responsibility of the impelemntor to make sure it is so).

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.

This method is only available if

  • I::Item implements PushInto<LuaState>, which means that it can be pushed onto the lua stack by value
  • I::Item::Err implements Into<Void>, which means that no error can happen during the attempt to push

If I::Item pushes a single value onto the stack, the resulting lua table is a lua sequence (a table with 1-based integer keys).

If I::Item pushes 2 values onto the stack, the resulting lua table is a regular lua table with the provided keys.

If I::Item pushes more than 2 values, the function returns Err(self).

Returns a PushGuard which captures self by value and stores the amount of values pushed onto the stack (exactly 1 – lua table).

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.

This method is only available if I::Item implements PushInto<LuaState>, which means that it can be pushed onto the lua stack by value.

If I::Item pushes a single value onto the stack, the resulting lua table is a lua sequence (a table with 1-based integer keys).

If I::Item pushes 2 values onto the stack, the resulting lua table is a regular lua table with the provided keys.

If I::Item pushes more than 2 values or an error happens during an attempt to push, the function returns Err((e, self)) where e is a PushIterErrorOf.

Returns a PushGuard which captures self by value and stores the amount of values pushed onto the stack (exactly 1 – lua table).

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.

This can also be sometimes used to catch other C++ exceptions although be careful with that.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl AsLua for *mut lua_State

source§

impl<T> AsLua for &T
where T: ?Sized + AsLua,

Implementors§

source§

impl AsLua for InsideCallback

source§

impl<D> AsLua for Lua<D>
where D: OnDrop,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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