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§
sourcefn try_push<T>(
self,
v: T
) -> Result<PushGuard<Self>, (<T as PushInto<Self>>::Err, Self)>where
Self: Sized,
T: PushInto<Self>,
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
sourcefn push<T>(self, v: T) -> PushGuard<Self>where
Self: Sized,
T: PushInto<Self>,
<T as PushInto<Self>>::Err: Into<Void>,
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.
sourcefn 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.
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).
sourcefn push_one<T>(self, v: T) -> PushGuard<Self>where
Self: Sized,
T: PushOneInto<Self>,
<T as PushInto<Self>>::Err: Into<Void>,
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
TimplementsPushOneInto, which means that it pushes a single value onto the stackT::ErrimplementsInto<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).
sourcefn 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 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::ItemimplementsPushInto<LuaState>, which means that it can be pushed onto the lua stack by valueI::Item::ErrimplementsInto<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).
sourcefn 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 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).
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>,
sourcefn pcall<F, R>(&self, f: F) -> Result<R, LuaError>where
F: FnOnce(StaticLua) -> R,
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.