pub unsafe fn init_gc_metatable_for<T: Any>(
    state: *mut ffi::lua_State,
    customize_fn: Option<fn(*mut ffi::lua_State) -> Result<()>>,
) -> Result<()> {
    check_stack(state, 6)?;

    let type_id = TypeId::of::<T>();
    let ref_addr = {
        let mut mt_cache = mlua_expect!(METATABLE_CACHE.lock(), "cannot lock metatable cache");
        mlua_assert!(
            mt_cache.capacity() - mt_cache.len() > 0,
            "out of metatable cache capacity"
        );
        mt_cache.insert(type_id, 0);
        &mt_cache[&type_id] as *const u8
    };

    push_table(state, 0, 3)?;

    ffi::lua_pushcfunction(state, userdata_destructor::<T>);
    rawset_field(state, -2, "__gc")?;

    ffi::lua_pushboolean(state, 0);
    rawset_field(state, -2, "__metatable")?;

    if let Some(f) = customize_fn {
        f(state)?;
    }

    protect_lua(state, 1, 0, |state| {
        ffi::lua_rawsetp(state, ffi::LUA_REGISTRYINDEX, ref_addr as *mut c_void)
    })?;

    Ok(())
}
// Initialize the internal (with __gc method) metatable for a type T.
// Uses 6 stack spaces and calls checkstack.
Initialize the internal (with __gc method) metatable for a type T.
Uses 6 stack spaces and calls checkstack.
Initialize the internal ( with __gc method ) metatable for a type T . Uses 6 stack spaces and calls checkstack .
pub unsafe fn init_gc_metatable_for<T: Any>(
    state: *mut ffi::lua_State,
    customize_fn: Option<fn(*mut ffi::lua_State) -> Result<()>>,
) -> Result<()> {
    check_stack(state, 6)?;
    let type_id = TypeId::of::<T>();
    let ref_addr = {
        let mut mt_cache = mlua_expect!(METATABLE_CACHE.lock(), "cannot lock metatable cache");
        mlua_assert!(
            mt_cache.capacity() - mt_cache.len() > 0,
            "out of metatable cache capacity"
        );
        mt_cache.insert(type_id, 0);
        &mt_cache[&type_id] as *const u8
    };
    push_table(state, 0, 3)?;
    ffi::lua_pushcfunction(state, userdata_destructor::<T>);
    rawset_field(state, -2, "__gc")?;
    ffi::lua_pushboolean(state, 0);
    rawset_field(state, -2, "__metatable")?;
    if let Some(f) = customize_fn {
        f(state)?;
    }
    protect_lua(state, 1, 0, |state| {
        ffi::lua_rawsetp(state, ffi::LUA_REGISTRYINDEX, ref_addr as *mut c_void)
    })?;
    Ok(())
}
pub unsafe fn init_gc_metatable_for < T : Any > ( state : * mut ffi :: lua_State , customize_fn : Option < fn ( * mut ffi :: lua_State ) -> Result < ( ) > > , ) -> Result < ( ) > { check_stack ( state , 6 ) ? ; let type_id = TypeId :: of :: < T > ( ) ; let ref_addr = { let mut mt_cache = mlua_expect ! ( METATABLE_CACHE lock ( ) " " ) ; mlua_assert ! ( mt_cache capacity ( ) mt_cache len ( ) 0 " " ) ; mt_cache . insert ( type_id , 0 ) ; & mt_cache [ & type_id ] as * const u8 } ; push_table ( state , 0 , 3 ) ? ; ffi :: lua_pushcfunction ( state , userdata_destructor :: < T > ) ; rawset_field ( state , - 2 , " " ) ? ; ffi :: lua_pushboolean ( state , 0 ) ; rawset_field ( state , - 2 , " " ) ? ; if let Some ( f ) = customize_fn { f ( state ) ? ; } protect_lua ( state , 1 , 0 , | state | { ffi :: lua_rawsetp ( state , ffi :: LUA_REGISTRYINDEX , ref_addr as * mut c_void ) } ) ? ; Ok ( ( ) ) }
Initialize the internal (with __gc method) metatable for a type T.
Uses 6 stack spaces and calls checkstack.
Initialize the internal ( with __gc method ) metatable for a type T . Uses 6 stack spaces and calls checkstack .
state
*mut ffi::lua_State
customize_fn
Option<fn(*mut ffi::lua_State) -> Result<()>>
state
*mut ffi::lua_State
customize_fn
Option<fn(*mut ffi::lua_State) -> Result<()>>