mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Initial implementation of owned Lua types
This commit is contained in:
+18
-1
@@ -3,7 +3,7 @@ use std::os::raw::c_int;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::ffi;
|
||||
use crate::types::LuaRef;
|
||||
use crate::types::{LuaOwnedRef, LuaRef};
|
||||
use crate::util::{check_stack, error_traceback_thread, pop_error, StackGuard};
|
||||
use crate::value::{FromLuaMulti, ToLuaMulti};
|
||||
|
||||
@@ -48,6 +48,17 @@ pub enum ThreadStatus {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Thread<'lua>(pub(crate) LuaRef<'lua>);
|
||||
|
||||
/// Owned handle to an internal Lua thread.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OwnedThread(pub(crate) LuaOwnedRef);
|
||||
|
||||
impl OwnedThread {
|
||||
/// Get borrowed handle to the underlying Lua thread.
|
||||
pub const fn to_ref(&self) -> Thread {
|
||||
Thread(self.0.to_ref())
|
||||
}
|
||||
}
|
||||
|
||||
/// Thread (coroutine) representation as an async [`Future`] or [`Stream`].
|
||||
///
|
||||
/// Requires `feature = "async"`
|
||||
@@ -333,6 +344,12 @@ impl<'lua> Thread<'lua> {
|
||||
protect_lua!(lua.state, 0, 0, |_| ffi::luaL_sandboxthread(thread))
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert this handle to owned version.
|
||||
#[inline]
|
||||
pub fn into_owned(self) -> OwnedThread {
|
||||
OwnedThread(self.0.into_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'lua> PartialEq for Thread<'lua> {
|
||||
|
||||
Reference in New Issue
Block a user