File tree Expand file tree Collapse file tree 6 files changed +43
-9
lines changed Expand file tree Collapse file tree 6 files changed +43
-9
lines changed Original file line number Diff line number Diff line change @@ -328,6 +328,14 @@ pub unsafe fn lua_getglobal_(L: *mut lua_State, var: *const c_char) {
328
328
lua_getfield_ ( L , LUA_GLOBALSINDEX , var)
329
329
}
330
330
331
+ #[ inline( always) ]
332
+ pub unsafe fn lua_tolightuserdata ( L : * mut lua_State , idx : c_int ) -> * mut c_void {
333
+ if lua_islightuserdata ( L , idx) != 0 {
334
+ return lua_touserdata ( L , idx) ;
335
+ }
336
+ ptr:: null_mut ( )
337
+ }
338
+
331
339
#[ inline( always) ]
332
340
pub unsafe fn lua_tostring ( L : * mut lua_State , i : c_int ) -> * const c_char {
333
341
lua_tolstring ( L , i, ptr:: null_mut ( ) )
Original file line number Diff line number Diff line change @@ -417,6 +417,14 @@ pub unsafe fn lua_pushglobaltable(L: *mut lua_State) {
417
417
lua_rawgeti_ ( L , LUA_REGISTRYINDEX , LUA_RIDX_GLOBALS as _ )
418
418
}
419
419
420
+ #[ inline( always) ]
421
+ pub unsafe fn lua_tolightuserdata ( L : * mut lua_State , idx : c_int ) -> * mut c_void {
422
+ if lua_islightuserdata ( L , idx) != 0 {
423
+ return lua_touserdata ( L , idx) ;
424
+ }
425
+ ptr:: null_mut ( )
426
+ }
427
+
420
428
#[ inline( always) ]
421
429
pub unsafe fn lua_tostring ( L : * mut lua_State , i : c_int ) -> * const c_char {
422
430
lua_tolstring ( L , i, ptr:: null_mut ( ) )
Original file line number Diff line number Diff line change @@ -424,6 +424,14 @@ pub unsafe fn lua_pushglobaltable(L: *mut lua_State) -> c_int {
424
424
lua_rawgeti ( L , LUA_REGISTRYINDEX , LUA_RIDX_GLOBALS )
425
425
}
426
426
427
+ #[ inline( always) ]
428
+ pub unsafe fn lua_tolightuserdata ( L : * mut lua_State , idx : c_int ) -> * mut c_void {
429
+ if lua_islightuserdata ( L , idx) != 0 {
430
+ return lua_touserdata ( L , idx) ;
431
+ }
432
+ ptr:: null_mut ( )
433
+ }
434
+
427
435
#[ inline( always) ]
428
436
pub unsafe fn lua_tostring ( L : * mut lua_State , i : c_int ) -> * const c_char {
429
437
lua_tolstring ( L , i, ptr:: null_mut ( ) )
Original file line number Diff line number Diff line change @@ -457,6 +457,14 @@ pub unsafe fn lua_pushglobaltable(L: *mut lua_State) -> c_int {
457
457
lua_rawgeti ( L , LUA_REGISTRYINDEX , LUA_RIDX_GLOBALS )
458
458
}
459
459
460
+ #[ inline( always) ]
461
+ pub unsafe fn lua_tolightuserdata ( L : * mut lua_State , idx : c_int ) -> * mut c_void {
462
+ if lua_islightuserdata ( L , idx) != 0 {
463
+ return lua_touserdata ( L , idx) ;
464
+ }
465
+ ptr:: null_mut ( )
466
+ }
467
+
460
468
#[ inline( always) ]
461
469
pub unsafe fn lua_tostring ( L : * mut lua_State , i : c_int ) -> * const c_char {
462
470
lua_tolstring ( L , i, ptr:: null_mut ( ) )
Original file line number Diff line number Diff line change @@ -2965,8 +2965,7 @@ impl Lua {
2965
2965
match fut. as_mut ( ) . poll ( & mut ctx) {
2966
2966
Poll :: Pending => {
2967
2967
ffi:: lua_pushnil ( state) ;
2968
- let pending = & ASYNC_POLL_PENDING as * const u8 as * mut c_void ;
2969
- ffi:: lua_pushlightuserdata ( state, pending) ;
2968
+ ffi:: lua_pushlightuserdata ( state, Lua :: poll_pending ( ) . 0 ) ;
2970
2969
Ok ( 2 )
2971
2970
}
2972
2971
Poll :: Ready ( nresults) => {
@@ -3069,6 +3068,14 @@ impl Lua {
3069
3068
mem:: replace ( & mut ( * self . extra . get ( ) ) . waker , waker)
3070
3069
}
3071
3070
3071
+ /// Returns internal `Poll::Pending` constant used for executing async callbacks.
3072
+ #[ cfg( feature = "async" ) ]
3073
+ #[ doc( hidden) ]
3074
+ #[ inline]
3075
+ pub fn poll_pending ( ) -> LightUserData {
3076
+ LightUserData ( & ASYNC_POLL_PENDING as * const u8 as * mut c_void )
3077
+ }
3078
+
3072
3079
pub ( crate ) unsafe fn make_userdata < T > ( & self , data : UserDataCell < T > ) -> Result < AnyUserData >
3073
3080
where
3074
3081
T : UserData + ' static ,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ use crate::{
15
15
16
16
#[ cfg( feature = "async" ) ]
17
17
use {
18
- crate :: { lua :: ASYNC_POLL_PENDING , value:: MultiValue } ,
18
+ crate :: value:: MultiValue ,
19
19
futures_util:: stream:: Stream ,
20
20
std:: {
21
21
future:: Future ,
@@ -530,12 +530,7 @@ where
530
530
#[ cfg( feature = "async" ) ]
531
531
#[ inline( always) ]
532
532
unsafe fn is_poll_pending ( state : * mut ffi:: lua_State ) -> bool {
533
- if ffi:: lua_islightuserdata ( state, -1 ) != 0 {
534
- let stack_ptr = ffi:: lua_touserdata ( state, -1 ) as * const u8 ;
535
- let pending_ptr = & ASYNC_POLL_PENDING as * const u8 ;
536
- return std:: ptr:: eq ( stack_ptr, pending_ptr) ;
537
- }
538
- false
533
+ ffi:: lua_tolightuserdata ( state, -1 ) == Lua :: poll_pending ( ) . 0
539
534
}
540
535
541
536
#[ cfg( feature = "async" ) ]
You can’t perform that action at this time.
0 commit comments