11use std:: cell:: UnsafeCell ;
2- use std:: fmt;
32use std:: os:: raw:: { c_int, c_void} ;
43use std:: rc:: Rc ;
54
65use crate :: error:: Result ;
76#[ cfg( not( feature = "luau" ) ) ]
87use crate :: hook:: Debug ;
9- use crate :: state:: { ExtraData , Lua , RawLua , WeakLua } ;
8+ use crate :: state:: { ExtraData , Lua , RawLua } ;
109
1110// Re-export mutex wrappers
1211pub ( crate ) use sync:: { ArcReentrantMutexGuard , ReentrantMutex , ReentrantMutexGuard , XRc , XWeak } ;
@@ -19,6 +18,7 @@ pub(crate) type BoxFuture<'a, T> = futures_util::future::LocalBoxFuture<'a, T>;
1918
2019pub use app_data:: { AppData , AppDataRef , AppDataRefMut } ;
2120pub use registry_key:: RegistryKey ;
21+ pub ( crate ) use value_ref:: ValueRef ;
2222#[ cfg( any( feature = "luau" , doc) ) ]
2323pub use vector:: Vector ;
2424
@@ -115,75 +115,10 @@ impl<T> MaybeSend for T {}
115115
116116pub ( crate ) struct DestructedUserdata ;
117117
118- pub ( crate ) struct ValueRef {
119- pub ( crate ) lua : WeakLua ,
120- pub ( crate ) index : c_int ,
121- pub ( crate ) drop : bool ,
122- }
123-
124- impl ValueRef {
125- #[ inline]
126- pub ( crate ) fn new ( lua : & RawLua , index : c_int ) -> Self {
127- ValueRef {
128- lua : lua. weak ( ) . clone ( ) ,
129- index,
130- drop : true ,
131- }
132- }
133-
134- #[ inline]
135- pub ( crate ) fn to_pointer ( & self ) -> * const c_void {
136- let lua = self . lua . lock ( ) ;
137- unsafe { ffi:: lua_topointer ( lua. ref_thread ( ) , self . index ) }
138- }
139-
140- /// Returns a copy of the value, which is valid as long as the original value is held.
141- #[ inline]
142- pub ( crate ) fn copy ( & self ) -> Self {
143- ValueRef {
144- lua : self . lua . clone ( ) ,
145- index : self . index ,
146- drop : false ,
147- }
148- }
149- }
150-
151- impl fmt:: Debug for ValueRef {
152- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
153- write ! ( f, "Ref({:p})" , self . to_pointer( ) )
154- }
155- }
156-
157- impl Clone for ValueRef {
158- fn clone ( & self ) -> Self {
159- unsafe { self . lua . lock ( ) . clone_ref ( self ) }
160- }
161- }
162-
163- impl Drop for ValueRef {
164- fn drop ( & mut self ) {
165- if self . drop {
166- if let Some ( lua) = self . lua . try_lock ( ) {
167- unsafe { lua. drop_ref ( self ) } ;
168- }
169- }
170- }
171- }
172-
173- impl PartialEq for ValueRef {
174- fn eq ( & self , other : & Self ) -> bool {
175- assert ! (
176- self . lua == other. lua,
177- "Lua instance passed Value created from a different main Lua state"
178- ) ;
179- let lua = self . lua . lock ( ) ;
180- unsafe { ffi:: lua_rawequal ( lua. ref_thread ( ) , self . index , other. index ) == 1 }
181- }
182- }
183-
184118mod app_data;
185119mod registry_key;
186120mod sync;
121+ mod value_ref;
187122
188123#[ cfg( any( feature = "luau" , doc) ) ]
189124mod vector;
0 commit comments