1
1
use std:: cell:: UnsafeCell ;
2
- use std:: fmt;
3
2
use std:: os:: raw:: { c_int, c_void} ;
4
3
use std:: rc:: Rc ;
5
4
6
5
use crate :: error:: Result ;
7
6
#[ cfg( not( feature = "luau" ) ) ]
8
7
use crate :: hook:: Debug ;
9
- use crate :: state:: { ExtraData , Lua , RawLua , WeakLua } ;
8
+ use crate :: state:: { ExtraData , Lua , RawLua } ;
10
9
11
10
// Re-export mutex wrappers
12
11
pub ( crate ) use sync:: { ArcReentrantMutexGuard , ReentrantMutex , ReentrantMutexGuard , XRc , XWeak } ;
@@ -19,6 +18,7 @@ pub(crate) type BoxFuture<'a, T> = futures_util::future::LocalBoxFuture<'a, T>;
19
18
20
19
pub use app_data:: { AppData , AppDataRef , AppDataRefMut } ;
21
20
pub use registry_key:: RegistryKey ;
21
+ pub ( crate ) use value_ref:: ValueRef ;
22
22
#[ cfg( any( feature = "luau" , doc) ) ]
23
23
pub use vector:: Vector ;
24
24
@@ -115,75 +115,10 @@ impl<T> MaybeSend for T {}
115
115
116
116
pub ( crate ) struct DestructedUserdata ;
117
117
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
-
184
118
mod app_data;
185
119
mod registry_key;
186
120
mod sync;
121
+ mod value_ref;
187
122
188
123
#[ cfg( any( feature = "luau" , doc) ) ]
189
124
mod vector;
0 commit comments