@@ -694,14 +694,16 @@ impl RawLua {
694694
695695 /// Pops a value from the Lua stack.
696696 ///
697- /// Uses 2 stack spaces, does not call `checkstack`.
697+ /// Uses up to 1 stack spaces, does not call `checkstack`.
698698 pub ( crate ) unsafe fn pop_value ( & self ) -> Value {
699699 let value = self . stack_value ( -1 , None ) ;
700700 ffi:: lua_pop ( self . state ( ) , 1 ) ;
701701 value
702702 }
703703
704704 /// Returns value at given stack index without popping it.
705+ ///
706+ /// Uses up to 1 stack spaces, does not call `checkstack`.
705707 pub ( crate ) unsafe fn stack_value ( & self , idx : c_int , type_hint : Option < c_int > ) -> Value {
706708 let state = self . state ( ) ;
707709 match type_hint. unwrap_or_else ( || ffi:: lua_type ( state, idx) ) {
@@ -757,25 +759,21 @@ impl RawLua {
757759 }
758760
759761 ffi:: LUA_TUSERDATA => {
760- let ref_thread = self . ref_thread ( ) ;
761- ffi:: lua_xpush ( state, ref_thread, idx) ;
762-
763762 // If the userdata is `WrappedFailure`, process it as an error or panic.
764763 let failure_mt_ptr = ( * self . extra . get ( ) ) . wrapped_failure_mt_ptr ;
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- }
764+ match get_internal_userdata :: < WrappedFailure > ( state, idx, failure_mt_ptr) . as_mut ( ) {
765+ Some ( WrappedFailure :: Error ( err) ) => Value :: Error ( Box :: new ( err. clone ( ) ) ) ,
770766 Some ( WrappedFailure :: Panic ( panic) ) => {
771- ffi:: lua_pop ( ref_thread, 1 ) ;
772767 if let Some ( panic) = panic. take ( ) {
773768 resume_unwind ( panic) ;
774769 }
775770 // Previously resumed panic?
776771 Value :: Nil
777772 }
778- _ => Value :: UserData ( AnyUserData ( self . pop_ref_thread ( ) ) ) ,
773+ _ => {
774+ ffi:: lua_xpush ( state, self . ref_thread ( ) , idx) ;
775+ Value :: UserData ( AnyUserData ( self . pop_ref_thread ( ) ) )
776+ }
779777 }
780778 }
781779
0 commit comments