Initial implementation of owned Lua types

This commit is contained in:
Alex Orlenko
2022-10-16 23:36:26 +01:00
parent 02c08c6350
commit bf79d9e75d
10 changed files with 267 additions and 39 deletions
+18 -1
View File
@@ -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> {