From 79635f29be4b41bff9c3e4e261fde05bc89cb7f7 Mon Sep 17 00:00:00 2001 From: kyren Date: Tue, 6 Feb 2018 00:41:51 -0500 Subject: [PATCH] Add method to check whether a RegistryKey is owned by a given `Lua` instance --- src/lua.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lua.rs b/src/lua.rs index c32775e..b03a37e 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -549,7 +549,7 @@ impl Lua { /// /// You MUST call this function to remove a value placed in the registry with /// `create_registry_value` - pub fn remove_registry_value<'lua>(&'lua self, key: RegistryKey) { + pub fn remove_registry_value(&self, key: RegistryKey) { unsafe { lua_assert!( self.state, @@ -574,6 +574,14 @@ impl Lua { } } + /// Returns true if the given `RegistryKey` was created by this `Lua` instance. + /// + /// Other than this one, methods that accept a `RegistryKey` will panic if passed a + /// `RegistryKey` that was not created with this `Lua` instance. + pub fn owns_registry_value(&self, key: &RegistryKey) -> bool { + unsafe { key.lua_id == (*self.extra()).lua_id } + } + // Uses 1 stack space, does not call checkstack pub(crate) unsafe fn push_value(&self, state: *mut ffi::lua_State, value: Value) { match value {