@@ -2269,73 +2269,55 @@ impl Lua {
2269
2269
extra. app_data . remove ( )
2270
2270
}
2271
2271
2272
+ /// Pushes a value that implements `IntoLua` onto the Lua stack.
2273
+ ///
2274
+ /// Uses 2 stack spaces, does not call checkstack.
2272
2275
#[ doc( hidden) ]
2273
2276
#[ inline( always) ]
2274
2277
pub unsafe fn push < ' lua > ( & ' lua self , value : impl IntoLua < ' lua > ) -> Result < ( ) > {
2275
2278
value. push_into_stack ( self )
2276
2279
}
2277
2280
2278
- /// Pushes a value onto the Lua stack.
2281
+ /// Pushes a `Value` onto the Lua stack.
2279
2282
///
2280
2283
/// Uses 2 stack spaces, does not call checkstack.
2281
2284
#[ doc( hidden) ]
2282
2285
pub unsafe fn push_value ( & self , value : Value ) -> Result < ( ) > {
2286
+ if let Value :: Error ( err) = value {
2287
+ let protect = !self . unlikely_memory_error ( ) ;
2288
+ return push_gc_userdata ( self . state ( ) , WrappedFailure :: Error ( err) , protect) ;
2289
+ }
2290
+ self . push_value_ref ( & value)
2291
+ }
2292
+
2293
+ /// Pushes a `&Value` (by reference) onto the Lua stack.
2294
+ ///
2295
+ /// Similar to [`Lua::push_value`], uses 2 stack spaces, does not call checkstack.
2296
+ pub ( crate ) unsafe fn push_value_ref ( & self , value : & Value ) -> Result < ( ) > {
2283
2297
let state = self . state ( ) ;
2284
2298
match value {
2285
- Value :: Nil => {
2286
- ffi:: lua_pushnil ( state) ;
2287
- }
2288
-
2289
- Value :: Boolean ( b) => {
2290
- ffi:: lua_pushboolean ( state, b as c_int ) ;
2291
- }
2292
-
2293
- Value :: LightUserData ( ud) => {
2294
- ffi:: lua_pushlightuserdata ( state, ud. 0 ) ;
2295
- }
2296
-
2297
- Value :: Integer ( i) => {
2298
- ffi:: lua_pushinteger ( state, i) ;
2299
- }
2300
-
2301
- Value :: Number ( n) => {
2302
- ffi:: lua_pushnumber ( state, n) ;
2303
- }
2304
-
2299
+ Value :: Nil => ffi:: lua_pushnil ( state) ,
2300
+ Value :: Boolean ( b) => ffi:: lua_pushboolean ( state, * b as c_int ) ,
2301
+ Value :: LightUserData ( ud) => ffi:: lua_pushlightuserdata ( state, ud. 0 ) ,
2302
+ Value :: Integer ( i) => ffi:: lua_pushinteger ( state, * i) ,
2303
+ Value :: Number ( n) => ffi:: lua_pushnumber ( state, * n) ,
2305
2304
#[ cfg( feature = "luau" ) ]
2306
2305
Value :: Vector ( v) => {
2307
2306
#[ cfg( not( feature = "luau-vector4" ) ) ]
2308
2307
ffi:: lua_pushvector ( state, v. x ( ) , v. y ( ) , v. z ( ) ) ;
2309
2308
#[ cfg( feature = "luau-vector4" ) ]
2310
2309
ffi:: lua_pushvector ( state, v. x ( ) , v. y ( ) , v. z ( ) , v. w ( ) ) ;
2311
2310
}
2312
-
2313
- Value :: String ( s) => {
2314
- self . push_ref ( & s. 0 ) ;
2315
- }
2316
-
2317
- Value :: Table ( t) => {
2318
- self . push_ref ( & t. 0 ) ;
2319
- }
2320
-
2321
- Value :: Function ( f) => {
2322
- self . push_ref ( & f. 0 ) ;
2323
- }
2324
-
2325
- Value :: Thread ( t) => {
2326
- self . push_ref ( & t. 0 ) ;
2327
- }
2328
-
2329
- Value :: UserData ( ud) => {
2330
- self . push_ref ( & ud. 0 ) ;
2331
- }
2332
-
2311
+ Value :: String ( s) => self . push_ref ( & s. 0 ) ,
2312
+ Value :: Table ( t) => self . push_ref ( & t. 0 ) ,
2313
+ Value :: Function ( f) => self . push_ref ( & f. 0 ) ,
2314
+ Value :: Thread ( t) => self . push_ref ( & t. 0 ) ,
2315
+ Value :: UserData ( ud) => self . push_ref ( & ud. 0 ) ,
2333
2316
Value :: Error ( err) => {
2334
2317
let protect = !self . unlikely_memory_error ( ) ;
2335
- push_gc_userdata ( state, WrappedFailure :: Error ( err) , protect) ?;
2318
+ push_gc_userdata ( state, WrappedFailure :: Error ( err. clone ( ) ) , protect) ?;
2336
2319
}
2337
2320
}
2338
-
2339
2321
Ok ( ( ) )
2340
2322
}
2341
2323
0 commit comments