Switch back to Luau userdata destructors defined in mlua-sys v0.6

This commit is contained in:
Alex Orlenko
2025-05-24 11:35:25 +01:00
parent f7f04d5180
commit 69ef08d4d2
7 changed files with 14 additions and 40 deletions
+1 -11
View File
@@ -437,18 +437,8 @@ pub(crate) unsafe extern "C-unwind" fn collect_userdata<T>(state: *mut ffi::lua_
// This method is called by Luau GC when it's time to collect the userdata.
#[cfg(feature = "luau")]
pub(crate) unsafe extern "C" fn collect_userdata<T>(
state: *mut ffi::lua_State,
ud: *mut std::os::raw::c_void,
) {
// Almost none Lua operations are allowed when destructor is running,
// so we need to set a flag to prevent calling any Lua functions
let extra = (*ffi::lua_callbacks(state)).userdata as *mut crate::state::ExtraData;
(*extra).running_userdata_gc = true;
// Luau does not support _any_ panics in destructors (they are declared as "C", NOT as "C-unwind"),
// so any panics will trigger `abort()`.
pub(crate) unsafe extern "C-unwind" fn collect_userdata<T>(ud: *mut std::os::raw::c_void) {
ptr::drop_in_place(ud as *mut T);
(*extra).running_userdata_gc = false;
}
// This method can be called by user or Lua GC to destroy the userdata.