Trait tlua::Index

source ·
pub trait Index<L>: AsRef<Object<L>>
where L: AsLua,
{ // Provided methods fn get<'lua, K, R>(&'lua self, key: K) -> Option<R> where L: 'lua, K: PushOneInto<LuaState>, K::Err: Into<Void>, R: LuaRead<PushGuard<&'lua L>> { ... } fn try_get<'lua, K, R>(&'lua self, key: K) -> Result<R, LuaError> where L: 'lua, K: PushOneInto<LuaState>, K::Err: Into<Void>, R: LuaRead<PushGuard<&'lua L>> { ... } fn into_get<K, R>(self, key: K) -> Result<R, Self> where Self: AsLua + Sized, K: PushOneInto<LuaState>, K::Err: Into<Void>, R: LuaRead<PushGuard<Self>> { ... } fn try_into_get<K, R>(self, key: K) -> Result<R, (Self, LuaError)> where Self: AsLua + Sized, K: PushOneInto<LuaState>, K::Err: Into<Void>, R: LuaRead<PushGuard<Self>> { ... } fn call_method<'lua, A, R>( &'lua self, name: &str, args: A ) -> Result<R, MethodCallError<A::Err>> where L: 'lua, Self: Push<LuaState>, Self::Err: Into<Void>, A: PushInto<LuaState>, R: LuaRead<PushGuard<Callable<PushGuard<&'lua L>>>> { ... } }
Expand description

Types implementing this trait represent a single lua value that can be indexed, i.e. a regular lua table or other value implementing __index metamethod.

Provided Methods§

source

fn get<'lua, K, R>(&'lua self, key: K) -> Option<R>
where L: 'lua, K: PushOneInto<LuaState>, K::Err: Into<Void>, R: LuaRead<PushGuard<&'lua L>>,

Loads a value from the table (or other object using the __index metamethod) given its index.

The index must implement the PushOneInto trait and the return type must implement the LuaRead trait. See the documentation at the crate root for more information.

source

fn try_get<'lua, K, R>(&'lua self, key: K) -> Result<R, LuaError>
where L: 'lua, K: PushOneInto<LuaState>, K::Err: Into<Void>, R: LuaRead<PushGuard<&'lua L>>,

Loads a value from the table (or other object using the __index metamethod) given its index.

Possible errors:
  • LuaError::ExecutionError if an error happened during the check that index is valid in self
  • LuaError::WrongType if the result lua value couldn’t be read as the expected rust type

The index must implement the PushOneInto trait and the return type must implement the LuaRead trait. See the documentation at the crate root for more information.

source

fn into_get<K, R>(self, key: K) -> Result<R, Self>
where Self: AsLua + Sized, K: PushOneInto<LuaState>, K::Err: Into<Void>, R: LuaRead<PushGuard<Self>>,

Loads a value in the table (or other object using the __index metamethod) given its index, with the result capturing the table by value.

See also Index::get

source

fn try_into_get<K, R>(self, key: K) -> Result<R, (Self, LuaError)>
where Self: AsLua + Sized, K: PushOneInto<LuaState>, K::Err: Into<Void>, R: LuaRead<PushGuard<Self>>,

Loads a value in the table (or other object using the __index metamethod) given its index, with the result capturing the table by value.

Possible errors:
  • LuaError::ExecutionError if an error happened during the check that index is valid in self
  • LuaError::WrongType if the result lua value couldn’t be read as the expected rust type

See also Index::get

source

fn call_method<'lua, A, R>( &'lua self, name: &str, args: A ) -> Result<R, MethodCallError<A::Err>>
where L: 'lua, Self: Push<LuaState>, Self::Err: Into<Void>, A: PushInto<LuaState>, R: LuaRead<PushGuard<Callable<PushGuard<&'lua L>>>>,

Calls the method called name of the table (or other indexable object) with the provided args.

Possible errors:

  • MethodCallError::NoSuchMethod in case self[name] is nil
  • MethodCallError::PushError if pushing args failed
  • MethodCallError::LuaError if error happened during the function call

Object Safety§

This trait is not object safe.

Implementors§

source§

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

source§

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

source§

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