@@ -702,8 +702,6 @@ impl RawLua {
702
702
}
703
703
704
704
/// Returns value at given stack index without popping it.
705
- ///
706
- /// Uses 2 stack spaces, does not call checkstack.
707
705
pub ( crate ) unsafe fn stack_value ( & self , idx : c_int , type_hint : Option < c_int > ) -> Value {
708
706
let state = self . state ( ) ;
709
707
match type_hint. unwrap_or_else ( || ffi:: lua_type ( state, idx) ) {
@@ -759,21 +757,25 @@ impl RawLua {
759
757
}
760
758
761
759
ffi:: LUA_TUSERDATA => {
760
+ let ref_thread = self . ref_thread ( ) ;
761
+ ffi:: lua_xpush ( state, ref_thread, idx) ;
762
+
762
763
// If the userdata is `WrappedFailure`, process it as an error or panic.
763
764
let failure_mt_ptr = ( * self . extra . get ( ) ) . wrapped_failure_mt_ptr ;
764
- match get_internal_userdata :: < WrappedFailure > ( state, idx, failure_mt_ptr) . as_mut ( ) {
765
- Some ( WrappedFailure :: Error ( err) ) => Value :: Error ( Box :: new ( err. clone ( ) ) ) ,
765
+ match get_internal_userdata :: < WrappedFailure > ( ref_thread, -1 , failure_mt_ptr) . as_mut ( ) {
766
+ Some ( WrappedFailure :: Error ( err) ) => {
767
+ ffi:: lua_pop ( ref_thread, 1 ) ;
768
+ Value :: Error ( Box :: new ( err. clone ( ) ) )
769
+ } ,
766
770
Some ( WrappedFailure :: Panic ( panic) ) => {
771
+ ffi:: lua_pop ( ref_thread, 1 ) ;
767
772
if let Some ( panic) = panic. take ( ) {
768
773
resume_unwind ( panic) ;
769
774
}
770
775
// Previously resumed panic?
771
776
Value :: Nil
772
777
}
773
- _ => {
774
- ffi:: lua_xpush ( state, self . ref_thread ( ) , idx) ;
775
- Value :: UserData ( AnyUserData ( self . pop_ref_thread ( ) ) )
776
- }
778
+ _ => Value :: UserData ( AnyUserData ( self . pop_ref_thread ( ) ) ) ,
777
779
}
778
780
}
779
781
0 commit comments