Actually unref scope created types from the registry AS WELL AS destructing them

This commit is contained in:
kyren 2018-02-09 07:27:12 -05:00
parent 84b009da03
commit 514abd5b82
2 changed files with 4 additions and 0 deletions

View File

@ -1080,6 +1080,8 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
ffi::LUA_REGISTRYINDEX, ffi::LUA_REGISTRYINDEX,
registry_id as ffi::lua_Integer, registry_id as ffi::lua_Integer,
); );
ffi::luaL_unref(state, ffi::LUA_REGISTRYINDEX, registry_id);
ffi::lua_getupvalue(state, -1, 1); ffi::lua_getupvalue(state, -1, 1);
let ud = take_userdata::<RefCell<Callback>>(state); let ud = take_userdata::<RefCell<Callback>>(state);
@ -1109,6 +1111,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
ffi::LUA_REGISTRYINDEX, ffi::LUA_REGISTRYINDEX,
registry_id as ffi::lua_Integer, registry_id as ffi::lua_Integer,
); );
ffi::luaL_unref(state, ffi::LUA_REGISTRYINDEX, registry_id);
Box::new(take_userdata::<RefCell<T>>(state)) Box::new(take_userdata::<RefCell<T>>(state))
})); }));
Ok(u) Ok(u)

View File

@ -614,6 +614,7 @@ fn scope_func() {
.unwrap(); .unwrap();
lua.globals().set("bad", f.clone()).unwrap(); lua.globals().set("bad", f.clone()).unwrap();
f.call::<_, ()>(()).unwrap(); f.call::<_, ()>(()).unwrap();
assert_eq!(Rc::strong_count(&rc), 2);
}); });
assert_eq!(rc.get(), 42); assert_eq!(rc.get(), 42);
assert_eq!(Rc::strong_count(&rc), 1); assert_eq!(Rc::strong_count(&rc), 1);