mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
74b4601b48
- Support global hooks inherited by new threads - Support thread hooks, where each thread can have its own hook This should also allow to enable hooks for async calls. Related to #489 #347
81 lines
2.1 KiB
Rust
81 lines
2.1 KiB
Rust
use std::any::Any;
|
|
use std::os::raw::c_void;
|
|
|
|
use crate::types::{Callback, CallbackUpvalue};
|
|
|
|
#[cfg(feature = "async")]
|
|
use crate::types::{AsyncCallback, AsyncCallbackUpvalue, AsyncPollUpvalue};
|
|
|
|
pub(crate) trait TypeKey: Any {
|
|
fn type_key() -> *const c_void;
|
|
}
|
|
|
|
impl TypeKey for String {
|
|
#[inline(always)]
|
|
fn type_key() -> *const c_void {
|
|
static STRING_TYPE_KEY: u8 = 0;
|
|
&STRING_TYPE_KEY as *const u8 as *const c_void
|
|
}
|
|
}
|
|
|
|
impl TypeKey for Callback {
|
|
#[inline(always)]
|
|
fn type_key() -> *const c_void {
|
|
static CALLBACK_TYPE_KEY: u8 = 0;
|
|
&CALLBACK_TYPE_KEY as *const u8 as *const c_void
|
|
}
|
|
}
|
|
|
|
impl TypeKey for CallbackUpvalue {
|
|
#[inline(always)]
|
|
fn type_key() -> *const c_void {
|
|
static CALLBACK_UPVALUE_TYPE_KEY: u8 = 0;
|
|
&CALLBACK_UPVALUE_TYPE_KEY as *const u8 as *const c_void
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "luau"))]
|
|
impl TypeKey for crate::types::HookCallback {
|
|
#[inline(always)]
|
|
fn type_key() -> *const c_void {
|
|
static HOOK_CALLBACK_TYPE_KEY: u8 = 0;
|
|
&HOOK_CALLBACK_TYPE_KEY as *const u8 as *const c_void
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "async")]
|
|
impl TypeKey for AsyncCallback {
|
|
#[inline(always)]
|
|
fn type_key() -> *const c_void {
|
|
static ASYNC_CALLBACK_TYPE_KEY: u8 = 0;
|
|
&ASYNC_CALLBACK_TYPE_KEY as *const u8 as *const c_void
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "async")]
|
|
impl TypeKey for AsyncCallbackUpvalue {
|
|
#[inline(always)]
|
|
fn type_key() -> *const c_void {
|
|
static ASYNC_CALLBACK_UPVALUE_TYPE_KEY: u8 = 0;
|
|
&ASYNC_CALLBACK_UPVALUE_TYPE_KEY as *const u8 as *const c_void
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "async")]
|
|
impl TypeKey for AsyncPollUpvalue {
|
|
#[inline(always)]
|
|
fn type_key() -> *const c_void {
|
|
static ASYNC_POLL_UPVALUE_TYPE_KEY: u8 = 0;
|
|
&ASYNC_POLL_UPVALUE_TYPE_KEY as *const u8 as *const c_void
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "async")]
|
|
impl TypeKey for Option<std::task::Waker> {
|
|
#[inline(always)]
|
|
fn type_key() -> *const c_void {
|
|
static WAKER_TYPE_KEY: u8 = 0;
|
|
&WAKER_TYPE_KEY as *const u8 as *const c_void
|
|
}
|
|
}
|