diff --git a/src/lua.rs b/src/lua.rs index 03485f2..a7c55b1 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -807,7 +807,9 @@ impl Lua { ffi::lua_rawset(state, -3); })?; - let id = ffi::luaL_ref(self.state, ffi::LUA_REGISTRYINDEX); + let id = gc_guard(self.state, || { + ffi::luaL_ref(self.state, ffi::LUA_REGISTRYINDEX) + }); (*registered_userdata).insert(TypeId::of::(), id); Ok(id) })