Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,38 @@ impl Lua {
R::from_stack_multi(nresults, &lua)
}

/// Runs callback with the inner RawLua value. It can be used to manually push and get values on the stack.
///
/// This function is safe because all unsafe actions with RawLua can only be done with unsafe
///
/// # Example
/// ```
/// # use mlua::{Lua, Result, FromLua, IntoLua};
/// # fn main() -> Result<()> {
/// let lua = Lua::new();
/// let n: i32 = {
/// let num = 11i32;
/// lua.exec_raw_lua(|lua| {
/// unsafe {
/// <i32 as IntoLua>::push_into_stack(num, lua)?;
/// }
///
/// let n = unsafe {
/// <i32 as FromLua>::from_stack(-1, lua)?
/// };
/// Result::Ok(n)
/// })
/// }?;
/// assert_eq!(n, 11);
/// # Ok(())
/// # }
/// ```
#[doc(hidden)]
pub fn exec_raw_lua<R>(&self, f: impl FnOnce(&RawLua) -> R) -> R {
let lua = self.lock();
f(&lua)
}

/// Loads the specified subset of the standard libraries into an existing Lua state.
///
/// Use the [`StdLib`] flags to specify the libraries you want to load.
Expand Down