summaryrefslogtreecommitdiff
path: root/src/lua.rs
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2023-02-15 09:20:03 +0000
committerAlex Orlenko <zxteam@protonmail.com>2023-02-15 09:20:03 +0000
commitb8e3290f356249d701ebdd2566deb55de2359da0 (patch)
treeb357ab1994bb39f683d4cc0bf89461ba79b86f8f /src/lua.rs
parent03ab8283429ee5ed57241bc5353e1f9c95b7be21 (diff)
downloadmlua-b8e3290f356249d701ebdd2566deb55de2359da0.zip
Update LuaRef/LuaOwnedRef
Move content of `Lua::make_owned_ref` into `LuaRef::into_owned` Add crate-visible `Lua::clone` function (not trait)
Diffstat (limited to 'src/lua.rs')
-rw-r--r--src/lua.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/lua.rs b/src/lua.rs
index 29639d3..50d16b7 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -2493,24 +2493,16 @@ impl Lua {
}
}
- pub(crate) fn drop_ref(&self, lref: &LuaRef) {
+ pub(crate) fn drop_ref_index(&self, index: c_int) {
unsafe {
let ref_thread = self.ref_thread();
ffi::lua_pushnil(ref_thread);
- ffi::lua_replace(ref_thread, lref.index);
- (*self.extra.get()).ref_free.push(lref.index);
+ ffi::lua_replace(ref_thread, index);
+ (*self.extra.get()).ref_free.push(index);
}
}
#[cfg(feature = "unstable")]
- pub(crate) fn make_owned_ref(&self, lref: LuaRef) -> crate::types::LuaOwnedRef {
- assert!(lref.drop, "Cannot turn non-drop reference into owned");
- let owned_ref = crate::types::LuaOwnedRef::new(Lua(self.0.clone()), lref.index);
- mem::forget(lref);
- owned_ref
- }
-
- #[cfg(feature = "unstable")]
pub(crate) fn adopt_owned_ref(&self, loref: crate::types::LuaOwnedRef) -> LuaRef {
assert!(
Arc::ptr_eq(&loref.lua.0, &self.0),
@@ -3041,6 +3033,12 @@ impl Lua {
.map(|x| x.as_ref().memory_limit == 0)
.unwrap_or_default()
}
+
+ #[cfg(feature = "unstable")]
+ #[inline]
+ pub(crate) fn clone(&self) -> Self {
+ Lua(Arc::clone(&self.0))
+ }
}
impl LuaInner {