Skip to content

Commit c9848d6

Browse files
committed
Update doc/example for (hidden) Lua::exec_raw_lua
1 parent 9126bb8 commit c9848d6

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/state.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -449,30 +449,27 @@ impl Lua {
449449
R::from_stack_multi(nresults, &lua)
450450
}
451451

452-
/// Runs callback with the inner RawLua value. It can be used to manually push and get values on
453-
/// the stack.
452+
/// Calls provided function passing a reference to the [`RawLua`] handle.
454453
///
455-
/// This function is safe because all unsafe actions with RawLua can only be done with unsafe
454+
/// Provided [`RawLua`] handle can be used to manually pushing/popping values to/from the stack.
456455
///
457456
/// # Example
458457
/// ```
459-
/// # use mlua::{Lua, Result, FromLua, IntoLua};
458+
/// # use mlua::{Lua, Result, FromLua, IntoLua, IntoLuaMulti};
460459
/// # fn main() -> Result<()> {
461460
/// let lua = Lua::new();
462461
/// let n: i32 = {
463-
/// let num = 11i32;
464-
/// lua.exec_raw_lua(|lua| {
465-
/// unsafe {
466-
/// <i32 as IntoLua>::push_into_stack(num, lua)?;
462+
/// let nums = (3, 4, 5);
463+
/// lua.exec_raw_lua(|rawlua| unsafe {
464+
/// nums.push_into_stack_multi(rawlua)?;
465+
/// let mut sum = 0;
466+
/// for _ in 0..3 {
467+
/// sum += rawlua.pop::<i32>()?;
467468
/// }
468-
///
469-
/// let n = unsafe {
470-
/// <i32 as FromLua>::from_stack(-1, lua)?
471-
/// };
472-
/// Result::Ok(n)
469+
/// Result::Ok(sum)
473470
/// })
474471
/// }?;
475-
/// assert_eq!(n, 11);
472+
/// assert_eq!(n, 12);
476473
/// # Ok(())
477474
/// # }
478475
/// ```

src/state/raw.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ impl RawLua {
731731
/// Pushes a value that implements `IntoLua` onto the Lua stack.
732732
///
733733
/// Uses up to 2 stack spaces to push a single value, does not call `checkstack`.
734+
#[allow(clippy::missing_safety_doc)]
734735
#[inline(always)]
735736
pub unsafe fn push(&self, value: impl IntoLua) -> Result<()> {
736737
value.push_into_stack(self)
@@ -739,6 +740,7 @@ impl RawLua {
739740
/// Pops a value that implements [`FromLua`] from the top of the Lua stack.
740741
///
741742
/// Uses up to 1 stack space, does not call `checkstack`.
743+
#[allow(clippy::missing_safety_doc)]
742744
#[inline(always)]
743745
pub unsafe fn pop<R: FromLua>(&self) -> Result<R> {
744746
let v = R::from_stack(-1, self)?;
@@ -749,6 +751,7 @@ impl RawLua {
749751
/// Pushes a `Value` (by reference) onto the Lua stack.
750752
///
751753
/// Uses up to 2 stack spaces, does not call `checkstack`.
754+
#[allow(clippy::missing_safety_doc)]
752755
pub unsafe fn push_value(&self, value: &Value) -> Result<()> {
753756
let state = self.state();
754757
match value {
@@ -783,6 +786,7 @@ impl RawLua {
783786
/// Pops a value from the Lua stack.
784787
///
785788
/// Uses up to 1 stack spaces, does not call `checkstack`.
789+
#[allow(clippy::missing_safety_doc)]
786790
#[inline]
787791
pub unsafe fn pop_value(&self) -> Value {
788792
let value = self.stack_value(-1, None);

src/util/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ where
197197
F: FnOnce(*mut ffi::lua_State) -> R,
198198
R: Copy,
199199
{
200-
struct Params<F, R: Copy> {
200+
struct Params<F, R> {
201201
function: Option<F>,
202202
result: MaybeUninit<R>,
203203
nresults: c_int,

0 commit comments

Comments
 (0)