diff options
Diffstat (limited to 'mlua-sys')
-rw-r--r-- | mlua-sys/src/luau/lua.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/mlua-sys/src/luau/lua.rs b/mlua-sys/src/luau/lua.rs index 596db0c..996f62e 100644 --- a/mlua-sys/src/luau/lua.rs +++ b/mlua-sys/src/luau/lua.rs @@ -2,7 +2,7 @@ use std::marker::{PhantomData, PhantomPinned}; use std::os::raw::{c_char, c_double, c_float, c_int, c_uint, c_void}; -use std::ptr; +use std::{mem, ptr}; // Option for multiple returns in 'lua_pcall' and 'lua_call' pub const LUA_MULTRET: c_int = -1; @@ -326,6 +326,15 @@ pub unsafe fn lua_newuserdata(L: *mut lua_State, sz: usize) -> *mut c_void { lua_newuserdatatagged(L, sz, 0) } +#[inline(always)] +pub unsafe fn lua_newuserdata_t<T>(L: *mut lua_State) -> *mut T { + unsafe extern "C-unwind" fn destructor<T>(ud: *mut c_void) { + ptr::drop_in_place(ud as *mut T); + } + + lua_newuserdatadtor(L, mem::size_of::<T>(), destructor::<T>) as *mut T +} + // TODO: lua_strlen #[inline(always)] |