pub struct Object<L> { /* private fields */ }Expand description
Implementations§
Source§impl<L: AsLua> Object<L>
impl<L: AsLua> Object<L>
Sourcepub fn read<'l, T>(&'l self, offset: i32) -> Result<T, LuaError>where
T: LuaRead<&'l Self>,
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]);pub fn guard(&self) -> &L
pub fn into_guard(self) -> L
pub fn index(&self) -> AbsoluteIndex
Trait Implementations§
Source§impl<L> AsLua for Object<L>where
L: AsLua,
impl<L> AsLua for Object<L>where
L: AsLua,
fn as_lua(&self) -> LuaState
Source§fn try_push<T>(
self,
v: T,
) -> Result<PushGuard<Self>, (<T as PushInto<Self>>::Err, Self)>
fn try_push<T>( self, v: T, ) -> Result<PushGuard<Self>, (<T as PushInto<Self>>::Err, Self)>
Try to push
v onto the lua stack. Read moreSource§fn try_push_one<T>(
self,
v: T,
) -> Result<PushGuard<Self>, (<T as PushInto<Self>>::Err, Self)>where
Self: Sized,
T: PushOneInto<Self>,
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 moreSource§fn push_iter<I>(self, iterator: I) -> Result<PushGuard<Self>, Self>
fn push_iter<I>(self, iterator: I) -> Result<PushGuard<Self>, Self>
Push
iterator onto the lua stack as a lua table. Read moreSource§fn try_push_iter<I>(
self,
iterator: I,
) -> Result<PushGuard<Self>, (PushIterErrorOf<I>, Self)>
fn try_push_iter<I>( self, iterator: I, ) -> Result<PushGuard<Self>, (PushIterErrorOf<I>, Self)>
Push
iterator onto the lua stack as a lua table. Read morefn read<T>(self) -> ReadResult<T, Self>
fn read_at<T>(self, index: i32) -> ReadResult<T, Self>
fn read_at_nz<T>(self, index: NonZeroI32) -> ReadResult<T, Self>
Source§impl<'a, L> From<CDataOnStack<'a, L>> for Object<L>
impl<'a, L> From<CDataOnStack<'a, L>> for Object<L>
Source§fn from(ud: CDataOnStack<'a, L>) -> Self
fn from(ud: CDataOnStack<'a, L>) -> Self
Converts to this type from the input type.
Source§impl<L> From<IndexableRW<L>> for Object<L>where
L: AsLua,
impl<L> From<IndexableRW<L>> for Object<L>where
L: AsLua,
Source§fn from(o: IndexableRW<L>) -> Self
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,
impl<L> From<LuaFunction<L>> for Object<L>where
L: AsLua,
Source§fn from(o: LuaFunction<L>) -> Self
fn from(o: LuaFunction<L>) -> Self
Converts to this type from the input type.
Source§impl<'a, T, L> From<UserdataOnStack<'a, T, L>> for Object<L>
impl<'a, T, L> From<UserdataOnStack<'a, T, L>> for Object<L>
Source§fn from(ud: UserdataOnStack<'a, T, L>) -> Self
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,
impl<L> LuaRead<L> for Object<L>where
L: AsLua,
Source§fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>
fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>
Reads the data from Lua at a given position.
fn n_values_expected() -> i32
Source§fn lua_read(lua: L) -> ReadResult<Self, L>
fn lua_read(lua: L) -> ReadResult<Self, L>
Reads the data from Lua.
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>
impl<L, K> Push<L> for Object<K>
Source§fn push_to_lua(&self, lua: L) -> PushResult<L, Self>
fn push_to_lua(&self, lua: L) -> PushResult<L, Self>
Pushes the value on the top of the stack. Read more
Source§impl<L, K> PushInto<L> for Object<K>
impl<L, K> PushInto<L> for Object<K>
type Err = Void
Source§fn push_into_lua(self, lua: L) -> PushIntoResult<L, Self>
fn push_into_lua(self, lua: L) -> PushIntoResult<L, Self>
Push the value into lua by value
Source§impl<T, L> TryFrom<Object<L>> for UserdataOnStack<'_, T, L>
impl<T, L> TryFrom<Object<L>> for UserdataOnStack<'_, T, L>
impl<L> PushOne<L> for Object<L>where
L: AsLua,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more