summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSondre Aasemoen <sondre@eons.io>2022-04-15 17:50:17 +0200
committerSondre Aasemoen <sondre@eons.io>2022-04-16 19:45:21 +0200
commita5ce0c1409d2e0f95f11c62dbb117b5e7f9a6ba5 (patch)
tree39e37e7074ee1ed10f701715460eab7329579ea8 /src
parentdba76f3994e69b30cdcc2ca15517f344a48e61cf (diff)
downloadmlua-a5ce0c1409d2e0f95f11c62dbb117b5e7f9a6ba5.zip
Add parking_lot dependency and feature
Diffstat (limited to 'src')
-rw-r--r--src/userdata_impl.rs47
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>>);