Revert 2e0e86dab2 (Update stack_value helper)

This commit is contained in:
Alex Orlenko
2025-06-16 21:33:47 +01:00
parent 3ea80b763d
commit ec10bf2a39
2 changed files with 10 additions and 12 deletions
+9 -11
View File
@@ -694,7 +694,7 @@ impl RawLua {
/// Pops a value from the Lua stack.
///
/// Uses 2 stack spaces, does not call `checkstack`.
/// Uses up to 1 stack spaces, does not call `checkstack`.
pub(crate) unsafe fn pop_value(&self) -> Value {
let value = self.stack_value(-1, None);
ffi::lua_pop(self.state(), 1);
@@ -702,6 +702,8 @@ impl RawLua {
}
/// Returns value at given stack index without popping it.
///
/// Uses up to 1 stack spaces, does not call `checkstack`.
pub(crate) unsafe fn stack_value(&self, idx: c_int, type_hint: Option<c_int>) -> Value {
let state = self.state();
match type_hint.unwrap_or_else(|| ffi::lua_type(state, idx)) {
@@ -757,25 +759,21 @@ impl RawLua {
}
ffi::LUA_TUSERDATA => {
let ref_thread = self.ref_thread();
ffi::lua_xpush(state, ref_thread, idx);
// If the userdata is `WrappedFailure`, process it as an error or panic.
let failure_mt_ptr = (*self.extra.get()).wrapped_failure_mt_ptr;
match get_internal_userdata::<WrappedFailure>(ref_thread, -1, failure_mt_ptr).as_mut() {
Some(WrappedFailure::Error(err)) => {
ffi::lua_pop(ref_thread, 1);
Value::Error(Box::new(err.clone()))
}
match get_internal_userdata::<WrappedFailure>(state, idx, failure_mt_ptr).as_mut() {
Some(WrappedFailure::Error(err)) => Value::Error(Box::new(err.clone())),
Some(WrappedFailure::Panic(panic)) => {
ffi::lua_pop(ref_thread, 1);
if let Some(panic) = panic.take() {
resume_unwind(panic);
}
// Previously resumed panic?
Value::Nil
}
_ => Value::UserData(AnyUserData(self.pop_ref_thread())),
_ => {
ffi::lua_xpush(state, self.ref_thread(), idx);
Value::UserData(AnyUserData(self.pop_ref_thread()))
}
}
}
+1 -1
View File
@@ -73,7 +73,7 @@ pub(crate) unsafe fn init_internal_metatable<T: TypeKey>(
Ok(())
}
// Uses 2 stack spaces, does not call checkstack
// Uses up to 1 stack space, does not call `checkstack`
pub(crate) unsafe fn get_internal_userdata<T: TypeKey>(
state: *mut ffi::lua_State,
index: c_int,