Skip to content

Commit ec10bf2

Browse files
committed
Revert 2e0e86d (Update stack_value helper)
1 parent 3ea80b7 commit ec10bf2

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/state/raw.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/util/userdata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub(crate) unsafe fn init_internal_metatable<T: TypeKey>(
7373
Ok(())
7474
}
7575

76-
// Uses 2 stack spaces, does not call checkstack
76+
// Uses up to 1 stack space, does not call `checkstack`
7777
pub(crate) unsafe fn get_internal_userdata<T: TypeKey>(
7878
state: *mut ffi::lua_State,
7979
index: c_int,

0 commit comments

Comments
 (0)