Remove generic from RawLua::push_userdata_metatable.

This should help to reduce amount of generated code.
This commit is contained in:
Alex Orlenko
2024-11-16 01:44:17 +00:00
parent cbf805f492
commit 89b68e2a24
6 changed files with 115 additions and 93 deletions
+15
View File
@@ -1,5 +1,9 @@
use std::cell::Cell;
use std::marker::PhantomData;
use std::os::raw::c_int;
use super::UserDataStorage;
use crate::util::{get_userdata, take_userdata};
// This is a trick to check if a type is `Sync` or not.
// It uses leaked specialization feature from stdlib.
@@ -29,3 +33,14 @@ pub(crate) fn is_sync<T>() -> bool {
.clone();
is_sync.get()
}
pub(super) unsafe extern "C-unwind" fn userdata_destructor<T>(state: *mut ffi::lua_State) -> c_int {
let ud = get_userdata::<UserDataStorage<T>>(state, -1);
if !(*ud).is_borrowed() {
take_userdata::<UserDataStorage<T>>(state);
ffi::lua_pushboolean(state, 1);
} else {
ffi::lua_pushboolean(state, 0);
}
1
}