pub fn create_registry_value<'lua, T: ToLua<'lua>>(&'lua self, t: T) -> Result<RegistryKey> {
        let t = t.to_lua(self)?;
        unsafe {
            let _sg = StackGuard::new(self.state);
            check_stack(self.state, 4)?;

            let unref_list = (*self.extra.get()).registry_unref_list.clone();
            self.push_value(t)?;

            // Try to reuse previously allocated RegistryKey
            let unref_list2 = unref_list.clone();
            let mut unref_list2 = mlua_expect!(unref_list2.lock(), "unref list poisoned");
            if let Some(registry_id) = unref_list2.as_mut().and_then(|x| x.pop()) {
                // It must be safe to replace the value without triggering memory error
                ffi::lua_rawseti(self.state, ffi::LUA_REGISTRYINDEX, registry_id as Integer);
                return Ok(RegistryKey {
                    registry_id,
                    unref_list,
                });
            }

            // Allocate a new RegistryKey
            let registry_id = protect_lua!(self.state, 1, 0, |state| {
                ffi::luaL_ref(state, ffi::LUA_REGISTRYINDEX)
            })?;

            Ok(RegistryKey {
                registry_id,
                unref_list,
            })
        }
    }
/// Place a value in the Lua registry with an auto-generated key.
///
/// This value will be available to Rust from all `Lua` instances which share the same main
/// state.
///
/// Be warned, garbage collection of values held inside the registry is not automatic, see
/// [`RegistryKey`] for more details.
/// However, dropped [`RegistryKey`]s automatically reused to store new values.
///
/// [`RegistryKey`]: crate::RegistryKey
Place a value in the Lua registry with an auto-generated key.
This value will be available to Rust from all `Lua` instances which share the same main
state.

Be warned, garbage collection of values held inside the registry is not automatic, see
[`RegistryKey`] for more details.
However, dropped [`RegistryKey`]s automatically reused to store new values.


Place a value in the Lua registry with an auto - generated key . This value will be available to Rust from all ` Lua ` instances which share the same main state . Be warned garbage collection of values held inside the registry is not automatic see [ ` RegistryKey ` ] for more details . However dropped [ ` RegistryKey ` ] s automatically reused to store new values .
pub fn create_registry_value<'lua, T: ToLua<'lua>>(&'lua self, t: T) -> Result<RegistryKey> {
        let t = t.to_lua(self)?;
        unsafe {
            let _sg = StackGuard::new(self.state);
            check_stack(self.state, 4)?;
            let unref_list = (*self.extra.get()).registry_unref_list.clone();
            self.push_value(t)?;
            // Try to reuse previously allocated RegistryKey
            let unref_list2 = unref_list.clone();
            let mut unref_list2 = mlua_expect!(unref_list2.lock(), "unref list poisoned");
            if let Some(registry_id) = unref_list2.as_mut().and_then(|x| x.pop()) {
                // It must be safe to replace the value without triggering memory error
                ffi::lua_rawseti(self.state, ffi::LUA_REGISTRYINDEX, registry_id as Integer);
                return Ok(RegistryKey {
                    registry_id,
                    unref_list,
                });
            }
            // Allocate a new RegistryKey
            let registry_id = protect_lua!(self.state, 1, 0, |state| {
                ffi::luaL_ref(state, ffi::LUA_REGISTRYINDEX)
            })?;
            Ok(RegistryKey {
                registry_id,
                unref_list,
            })
        }
    }
pub fn create_registry_value < ' lua , T : ToLua < ' lua > > ( & ' lua self , t : T ) -> Result < RegistryKey > { let t = t . to_lua ( self ) ? ; unsafe { let _sg = StackGuard :: new ( self . state ) ; check_stack ( self . state , 4 ) ? ; let unref_list = ( * self . extra . get ( ) ) . registry_unref_list . clone ( ) ; self . push_value ( t ) ? ; // Try to reuse previously allocated RegistryKey let unref_list2 = unref_list . clone ( ) ; let mut unref_list2 = mlua_expect ! ( unref_list2 lock ( ) " " ) ; if let Some ( registry_id ) = unref_list2 . as_mut ( ) . and_then ( | x | x . pop ( ) ) { // It must be safe to replace the value without triggering memory error ffi :: lua_rawseti ( self . state , ffi :: LUA_REGISTRYINDEX , registry_id as Integer ) ; return Ok ( RegistryKey { registry_id , unref_list , } ) ; } // Allocate a new RegistryKey let registry_id = protect_lua ! ( self state 1 0 state { ffi luaL_ref ( state ffi LUA_REGISTRYINDEX ) } ) ? ; Ok ( RegistryKey { registry_id , unref_list , } ) } }
Place a value in the Lua registry with an auto-generated key.
Place a value in the Lua registry with an auto - generated key .
&'lua self
t
T
&'lua self
t
T