diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2024-06-24 23:49:10 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2024-06-24 23:49:10 +0100 |
commit | 0314d0567f775244fa867cc6f4993551cd42d63c (patch) | |
tree | 3ab6e7795224cd860b26fee42c9449b16c73b18b | |
parent | 494dc75ddacb13f3e20d9a3c32f9e5f8a6facd34 (diff) | |
download | mlua-0314d0567f775244fa867cc6f4993551cd42d63c.zip |
Move userdata-related top-level modules into the userdata module
-rw-r--r-- | src/lib.rs | 9 | ||||
-rw-r--r-- | src/lua.rs | 7 | ||||
-rw-r--r-- | src/userdata.rs | 13 | ||||
-rw-r--r-- | src/userdata/cell.rs (renamed from src/userdata_cell.rs) | 21 | ||||
-rw-r--r-- | src/userdata/ext.rs (renamed from src/userdata_ext.rs) | 0 | ||||
-rw-r--r-- | src/userdata/registry.rs (renamed from src/userdata_impl.rs) | 3 |
6 files changed, 33 insertions, 20 deletions
@@ -96,9 +96,6 @@ mod table; mod thread; mod types; mod userdata; -mod userdata_cell; -mod userdata_ext; -mod userdata_impl; mod util; mod value; @@ -119,11 +116,9 @@ pub use crate::table::{Table, TableExt, TablePairs, TableSequence}; pub use crate::thread::{Thread, ThreadStatus}; pub use crate::types::{AppDataRef, AppDataRefMut, Integer, LightUserData, Number, RegistryKey}; pub use crate::userdata::{ - AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMetatable, UserDataMethods, + AnyUserData, AnyUserDataExt, MetaMethod, UserData, UserDataFields, UserDataMetatable, + UserDataMethods, UserDataRef, UserDataRefMut, UserDataRegistry, }; -pub use crate::userdata_cell::{UserDataRef, UserDataRefMut}; -pub use crate::userdata_ext::AnyUserDataExt; -pub use crate::userdata_impl::UserDataRegistry; pub use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, MultiValue, Nil, Value}; #[cfg(not(feature = "luau"))] @@ -30,9 +30,10 @@ use crate::types::{ DestructedUserdata, Integer, LightUserData, MaybeSend, Number, RegistryKey, SubtypeId, ValueRef, }; -use crate::userdata::{AnyUserData, MetaMethod, UserData}; -use crate::userdata_cell::{UserDataRef, UserDataVariant}; -use crate::userdata_impl::{UserDataProxy, UserDataRegistry}; +use crate::userdata::{ + AnyUserData, MetaMethod, UserData, UserDataProxy, UserDataRef, UserDataRegistry, + UserDataVariant, +}; use crate::util::{ self, assert_stack, check_stack, error_traceback, get_destructed_userdata_metatable, get_gc_metatable, get_gc_userdata, get_main_state, get_userdata, init_error_registry, diff --git a/src/userdata.rs b/src/userdata.rs index b21000c..1100dc3 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -20,10 +20,15 @@ use crate::lua::{Lua, LuaGuard}; use crate::string::String; use crate::table::{Table, TablePairs}; use crate::types::{MaybeSend, SubtypeId, ValueRef}; -use crate::userdata_cell::{UserDataRef, UserDataRefMut, UserDataVariant}; use crate::util::{check_stack, get_userdata, take_userdata, StackGuard}; use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Value}; -use crate::UserDataRegistry; + +// Re-export for convenience +pub(crate) use cell::UserDataVariant; +pub use cell::{UserDataRef, UserDataRefMut}; +pub use ext::AnyUserDataExt; +pub(crate) use registry::UserDataProxy; +pub use registry::UserDataRegistry; #[cfg(feature = "lua54")] pub(crate) const USER_VALUE_MAXSLOT: usize = 8; @@ -1181,6 +1186,10 @@ where } } +mod cell; +mod ext; +mod registry; + // #[cfg(test)] // mod assertions { // use super::*; diff --git a/src/userdata_cell.rs b/src/userdata/cell.rs index 59b4503..7205958 100644 --- a/src/userdata_cell.rs +++ b/src/userdata/cell.rs @@ -202,7 +202,10 @@ impl<T: 'static> FromLua for UserDataRef<T> { unsafe fn from_stack(idx: c_int, lua: &LuaInner) -> Result<Self> { let type_id = lua.get_userdata_type_id(idx)?; match type_id { - Some(type_id) if type_id == TypeId::of::<T>() => lua.get_userdata_ref(idx), + Some(type_id) if type_id == TypeId::of::<T>() => { + let guard = lua.lua().lock_arc(); + (*get_userdata::<UserDataVariant<T>>(lua.state(), idx)).try_make_ref(guard) + } _ => Err(Error::UserDataTypeMismatch), } } @@ -348,11 +351,13 @@ impl<'a, T> Deref for UserDataBorrowRef<'a, T> { } } -impl<'a, T> UserDataBorrowRef<'a, T> { +impl<'a, T> TryFrom<&'a UserDataVariant<T>> for UserDataBorrowRef<'a, T> { + type Error = Error; + #[inline(always)] - pub(crate) fn try_from(variant: &'a UserDataVariant<T>) -> Result<Self> { + fn try_from(variant: &'a UserDataVariant<T>) -> Result<Self> { set_reading(variant.flag())?; - Ok(UserDataBorrowRef(&variant)) + Ok(UserDataBorrowRef(variant)) } } @@ -381,11 +386,13 @@ impl<'a, T> DerefMut for UserDataBorrowMut<'a, T> { } } -impl<'a, T> UserDataBorrowMut<'a, T> { +impl<'a, T> TryFrom<&'a UserDataVariant<T>> for UserDataBorrowMut<'a, T> { + type Error = Error; + #[inline(always)] - pub(crate) fn try_from(variant: &'a UserDataVariant<T>) -> Result<Self> { + fn try_from(variant: &'a UserDataVariant<T>) -> Result<Self> { set_writing(variant.flag())?; - Ok(UserDataBorrowMut(&variant)) + Ok(UserDataBorrowMut(variant)) } } diff --git a/src/userdata_ext.rs b/src/userdata/ext.rs index 0863d9b..0863d9b 100644 --- a/src/userdata_ext.rs +++ b/src/userdata/ext.rs diff --git a/src/userdata_impl.rs b/src/userdata/registry.rs index b552778..147f679 100644 --- a/src/userdata_impl.rs +++ b/src/userdata/registry.rs @@ -11,10 +11,11 @@ use crate::error::{Error, Result}; use crate::lua::Lua; use crate::types::{Callback, MaybeSend}; use crate::userdata::{AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMethods}; -use crate::userdata_cell::{UserDataBorrowMut, UserDataBorrowRef, UserDataVariant}; use crate::util::{get_userdata, short_type_name}; use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Value}; +use super::cell::{UserDataBorrowMut, UserDataBorrowRef, UserDataVariant}; + #[cfg(not(feature = "send"))] use std::rc::Rc; |