summaryrefslogtreecommitdiff
path: root/src/function.rs
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2022-10-16 23:36:26 +0100
committerAlex Orlenko <zxteam@protonmail.com>2022-12-18 00:35:41 +0000
commitbf79d9e75dabaed9278084f49fb0a162002eb8a8 (patch)
tree6e1f24d1a3b7021a4bcef75b40ce7483e3d8ce48 /src/function.rs
parent02c08c6350092f7c94d40251e649e0e1116f2374 (diff)
downloadmlua-bf79d9e75dabaed9278084f49fb0a162002eb8a8.zip
Initial implementation of owned Lua types
Diffstat (limited to 'src/function.rs')
-rw-r--r--src/function.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/function.rs b/src/function.rs
index 8fb8d28..a981007 100644
--- a/src/function.rs
+++ b/src/function.rs
@@ -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> {