diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2022-04-17 01:38:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-17 01:38:03 +0100 |
commit | d77c0e3b8d497898a95f0084a3288b4b48a91de7 (patch) | |
tree | 36b42cb47bbd818b11760c244d216efaeaf6f72b /src | |
parent | 3904213ed078aa1263dd20eb9be5642180591c95 (diff) | |
parent | a5ce0c1409d2e0f95f11c62dbb117b5e7f9a6ba5 (diff) | |
download | mlua-d77c0e3b8d497898a95f0084a3288b4b48a91de7.zip |
Merge pull request #147 from sondr3/parking_lot
Add parking_lot dependency and feature
Diffstat (limited to 'src')
-rw-r--r-- | src/userdata_impl.rs | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/userdata_impl.rs b/src/userdata_impl.rs index a535245..9ab3757 100644 --- a/src/userdata_impl.rs +++ b/src/userdata_impl.rs @@ -246,11 +246,23 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> { let ud = ud.try_lock().map_err(|_| Error::UserDataBorrowError)?; method(lua, &ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) } + #[cfg(feature = "parking_lot")] + Some(id) if id == TypeId::of::<Arc<parking_lot::Mutex<T>>>() => { + let ud = get_userdata_ref::<Arc<parking_lot::Mutex<T>>>(lua.state)?; + let ud = ud.try_lock().ok_or(Error::UserDataBorrowError)?; + method(lua, &ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) + } Some(id) if id == TypeId::of::<Arc<RwLock<T>>>() => { let ud = get_userdata_ref::<Arc<RwLock<T>>>(lua.state)?; let ud = ud.try_read().map_err(|_| Error::UserDataBorrowError)?; method(lua, &ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) } + #[cfg(feature = "parking_lot")] + Some(id) if id == TypeId::of::<Arc<parking_lot::RwLock<T>>>() => { + let ud = get_userdata_ref::<Arc<parking_lot::RwLock<T>>>(lua.state)?; + let ud = ud.try_read().ok_or(Error::UserDataBorrowError)?; + method(lua, &ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) + } _ => Err(Error::UserDataTypeMismatch), } } @@ -297,14 +309,24 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> { } Some(id) if id == TypeId::of::<Arc<Mutex<T>>>() => { let ud = get_userdata_mut::<Arc<Mutex<T>>>(lua.state)?; - let mut ud = - ud.try_lock().map_err(|_| Error::UserDataBorrowMutError)?; + let mut ud = ud.try_lock().map_err(|_| Error::UserDataBorrowError)?; + method(lua, &mut ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) + } + #[cfg(feature = "parking_lot")] + Some(id) if id == TypeId::of::<Arc<parking_lot::Mutex<T>>>() => { + let ud = get_userdata_mut::<Arc<parking_lot::Mutex<T>>>(lua.state)?; + let mut ud = ud.try_lock().ok_or(Error::UserDataBorrowError)?; method(lua, &mut ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) } Some(id) if id == TypeId::of::<Arc<RwLock<T>>>() => { let ud = get_userdata_mut::<Arc<RwLock<T>>>(lua.state)?; - let mut ud = - ud.try_write().map_err(|_| Error::UserDataBorrowMutError)?; + let mut ud = ud.try_write().map_err(|_| Error::UserDataBorrowError)?; + method(lua, &mut ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) + } + #[cfg(feature = "parking_lot")] + Some(id) if id == TypeId::of::<Arc<parking_lot::RwLock<T>>>() => { + let ud = get_userdata_mut::<Arc<parking_lot::RwLock<T>>>(lua.state)?; + let mut ud = ud.try_write().ok_or(Error::UserDataBorrowError)?; method(lua, &mut ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) } _ => Err(Error::UserDataTypeMismatch), @@ -354,11 +376,24 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> { let ud = ud.try_lock().map_err(|_| Error::UserDataBorrowError)?; Ok(method(lua, ud.clone(), A::from_lua_multi(args, lua)?)) } + #[cfg(feature = "parking_lot")] + Some(id) if id == TypeId::of::<Arc<parking_lot::Mutex<T>>>() => { + let ud = get_userdata_ref::<Arc<parking_lot::Mutex<T>>>(lua.state)?; + let ud = ud.try_lock().ok_or(Error::UserDataBorrowError)?; + Ok(method(lua, ud.clone(), A::from_lua_multi(args, lua)?)) + } Some(id) if id == TypeId::of::<Arc<RwLock<T>>>() => { let ud = get_userdata_ref::<Arc<RwLock<T>>>(lua.state)?; let ud = ud.try_read().map_err(|_| Error::UserDataBorrowError)?; Ok(method(lua, ud.clone(), A::from_lua_multi(args, lua)?)) } + #[cfg(feature = "parking_lot")] + Some(id) if id == TypeId::of::<Arc<parking_lot::RwLock<T>>>() => { + let ud = + get_userdata_ref::<Arc<parking_lot::RwLock<T>>>(lua.state)?; + let ud = ud.try_read().ok_or(Error::UserDataBorrowError)?; + Ok(method(lua, ud.clone(), A::from_lua_multi(args, lua)?)) + } _ => Err(Error::UserDataTypeMismatch), } } @@ -581,3 +616,7 @@ macro_rules! lua_userdata_impl { lua_userdata_impl!(Rc<RefCell<T>>); lua_userdata_impl!(Arc<Mutex<T>>); lua_userdata_impl!(Arc<RwLock<T>>); +#[cfg(feature = "parking_lot")] +lua_userdata_impl!(Arc<parking_lot::Mutex<T>>); +#[cfg(feature = "parking_lot")] +lua_userdata_impl!(Arc<parking_lot::RwLock<T>>); |