Implement task handle awaiting

This commit is contained in:
2025-06-26 20:18:16 +10:00
parent 9338be7eb0
commit 8a74ade6a6
2 changed files with 67 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ use std::{
ffi::{CStr, CString, NulError},
fmt,
marker::PhantomData,
mem::ManuallyDrop,
ops::{Deref, DerefMut},
os::raw::{c_char, c_int, c_void},
pin::Pin,
@@ -35,6 +36,11 @@ pub fn url() -> &'static str {
LUAJIT_URL.to_str().unwrap()
}
// reexport constants
pub use luajit_sys::{
LUA_ENVIRONINDEX, LUA_GLOBALSINDEX, LUA_MULTRET, LUA_NOREF, LUA_REFNIL, LUA_REGISTRYINDEX,
};
/// Lua error.
#[derive(Debug, Error)]
#[non_exhaustive]
@@ -477,6 +483,19 @@ pub struct Ref {
key: c_int,
}
impl Ref {
/// Consumes this ref and returns the original key used to create the ref.
///
/// This key can be used to index into the registry table ([`LUA_REGISTRYINDEX`]) to retrieve
/// the referenced value. The key can be converted back into a ref using
/// [`State::new_ref_unchecked`].
pub fn into_raw(self) -> c_int {
let Self { ref mut state, key } = *ManuallyDrop::new(self);
unsafe { ptr::drop_in_place(state) }
key
}
}
impl Drop for Ref {
fn drop(&mut self) {
// SAFETY: luaL_unref is guaranteed to not fail
@@ -871,7 +890,7 @@ impl Stack {
/// array-part, these values are **not** cleared. The number of values popped is returned, which
/// is always equal to `n`.
///
/// This method does not invoke any metamethods.
/// This method does not invoke any metamethods. The table is not popped from the stack.
///
/// Equivalent to `table.pack(...)`.
///
@@ -907,7 +926,8 @@ impl Stack {
/// pushed at the top of the stack in ascending order. If `i > j`, then nothing is pushed.
/// Otherwise, `j - i + 1` values are pushed, and the number of values pushed is returned.
///
/// This method does not invoke any metamethods.
/// This method does not invoke any metamethods. The table is not popped from the stack or
/// altered in any way.
///
/// Equivalent to `table.unpack(list, i, j)`.
///