mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Revert 2e0e86dab2 (Update stack_value helper)
This commit is contained in:
+9
-11
@@ -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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user