@@ -504,11 +504,9 @@ impl Lua {
504
504
/// value previously placed by `create_registry_value`.
505
505
pub fn registry_value < ' lua , T : FromLua < ' lua > > ( & ' lua self , key : & RegistryKey ) -> Result < T > {
506
506
unsafe {
507
- lua_assert ! (
508
- self . state,
509
- Arc :: ptr_eq( & key. drop_list, & ( * self . extra( ) ) . registry_drop_list) ,
510
- "Lua instance passed RegistryKey created from a different Lua"
511
- ) ;
507
+ if !Arc :: ptr_eq ( & key. drop_list , & ( * self . extra ( ) ) . registry_drop_list ) {
508
+ return Err ( Error :: MismatchedRegistryKey ) ;
509
+ }
512
510
513
511
stack_err_guard ( self . state , 0 , || {
514
512
check_stack ( self . state , 1 ) ;
@@ -528,25 +526,25 @@ impl Lua {
528
526
/// `create_registry_value`. In addition to manual `RegistryKey` removal, you can also call
529
527
/// `expire_registry_values` to automatically remove values from the registry whose
530
528
/// `RegistryKey`s have been dropped.
531
- pub fn remove_registry_value ( & self , mut key : RegistryKey ) {
529
+ pub fn remove_registry_value ( & self , mut key : RegistryKey ) -> Result < ( ) > {
532
530
unsafe {
533
- lua_assert ! (
534
- self . state,
535
- Arc :: ptr_eq( & key. drop_list, & ( * self . extra( ) ) . registry_drop_list) ,
536
- "Lua instance passed RegistryKey created from a different Lua"
537
- ) ;
531
+ if !Arc :: ptr_eq ( & key. drop_list , & ( * self . extra ( ) ) . registry_drop_list ) {
532
+ return Err ( Error :: MismatchedRegistryKey ) ;
533
+ }
538
534
539
535
ffi:: luaL_unref ( self . state , ffi:: LUA_REGISTRYINDEX , key. registry_id ) ;
540
536
// Don't adding to the registry drop list when dropping the key
541
537
key. registry_id = ffi:: LUA_REFNIL ;
538
+ Ok ( ( ) )
542
539
}
543
540
}
544
541
545
542
/// Returns true if the given `RegistryKey` was created by a `Lua` which shares the underlying
546
543
/// main state with this `Lua` instance.
547
544
///
548
- /// Other than this, methods that accept a `RegistryKey` will panic if passed a `RegistryKey`
549
- /// that was not created with a matching `Lua` state.
545
+ /// Other than this, methods that accept a `RegistryKey` will return
546
+ /// `Error::MismatchedRegistryKey` if passed a `RegistryKey` that was not created with a
547
+ /// matching `Lua` state.
550
548
pub fn owns_registry_value ( & self , key : & RegistryKey ) -> bool {
551
549
unsafe { Arc :: ptr_eq ( & key. drop_list , & ( * self . extra ( ) ) . registry_drop_list ) }
552
550
}
0 commit comments