-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
I didn't call drop for the callback when I removed C. Can I change it this way
type Callback<'f> =
Box<dyn Fn(*mut State) -> Result<c_int, crate::Error> + 'f>;
/// Removes the function reference stored in the Lua registry
pub fn remove(lua_ref: c_int) {
unsafe {
crate::with_state(|lstate| {
ffi::lua_rawgeti(lstate, ffi::LUA_REGISTRYINDEX, lua_ref);
ptr::drop_in_place(get_callback(lstate));
ffi::lua_pop(lstate, 1);
ffi::luaL_unref(lstate, ffi::LUA_REGISTRYINDEX, lua_ref)
})
}
}
unsafe fn get_callback(lstate: *mut State) -> *mut Callback<'static> {
let idx = ffi::lua_upvalueindex(1);
ffi::lua_touserdata(lstate, idx) as *mut Callback
}Metadata
Metadata
Assignees
Labels
No labels