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
@@ -5,7 +5,7 @@ use std::slice;
use crate::error::{Error, Result};
use crate::ffi;
use crate::types::LuaRef;
use crate::types::{LuaOwnedRef, LuaRef};
use crate::util::{
assert_stack, check_stack, error_traceback, pop_error, ptr_to_cstr_bytes, StackGuard,
};
@@ -18,6 +18,17 @@ use {futures_core::future::LocalBoxFuture, futures_util::future};
#[derive(Clone, Debug)]
pub struct Function<'lua>(pub(crate) LuaRef<'lua>);
/// Owned handle to an internal Lua function.
#[derive(Clone, Debug)]
pub struct OwnedFunction(pub(crate) LuaOwnedRef);
impl OwnedFunction {
/// Get borrowed handle to the underlying Lua function.
pub const fn to_ref(&self) -> Function {
Function(self.0.to_ref())
}
}
#[derive(Clone, Debug)]
pub struct FunctionInfo {
pub name: Option<Vec<u8>>,
@@ -373,6 +384,12 @@ impl<'lua> Function<'lua> {
ffi::lua_getcoverage(lua.state, -1, func_ptr, callback::<F>);
}
}
/// Convert this handle to owned version.
#[inline]
pub fn into_owned(self) -> OwnedFunction {
OwnedFunction(self.0.into_owned())
}
}
impl<'lua> PartialEq for Function<'lua> {