@@ -22,10 +22,10 @@ use crate::types::{
22
22
} ;
23
23
use crate :: userdata:: { AnyUserData , MetaMethod , UserData , UserDataMethods , UserDataWrapped } ;
24
24
use crate :: util:: {
25
- assert_stack, callback_error, check_stack, get_gc_userdata, get_main_state,
26
- get_meta_gc_userdata , get_wrapped_error, init_error_registry, init_gc_metatable_for,
27
- init_userdata_metatable , pop_error, protect_lua, protect_lua_closure, push_gc_userdata,
28
- push_meta_gc_userdata , push_string, push_userdata, push_wrapped_error, StackGuard ,
25
+ assert_stack, callback_error, check_stack, get_gc_userdata, get_main_state, get_userdata ,
26
+ get_wrapped_error, init_error_registry, init_gc_metatable_for, init_userdata_metatable ,
27
+ pop_error, protect_lua, protect_lua_closure, push_gc_userdata, push_meta_gc_userdata ,
28
+ push_string, push_userdata, push_wrapped_error, StackGuard ,
29
29
} ;
30
30
use crate :: value:: { FromLua , FromLuaMulti , MultiValue , Nil , ToLua , ToLuaMulti , Value } ;
31
31
@@ -1504,9 +1504,10 @@ impl Lua {
1504
1504
}
1505
1505
1506
1506
pub ( crate ) unsafe fn userdata_metatable < T : ' static + UserData > ( & self ) -> Result < c_int > {
1507
+ let type_id = TypeId :: of :: < T > ( ) ;
1507
1508
if let Some ( table_id) = mlua_expect ! ( self . extra. lock( ) , "extra is poisoned" )
1508
1509
. registered_userdata
1509
- . get ( & TypeId :: of :: < T > ( ) )
1510
+ . get ( & type_id )
1510
1511
{
1511
1512
return Ok ( * table_id) ;
1512
1513
}
@@ -1567,7 +1568,7 @@ impl Lua {
1567
1568
} ) ?;
1568
1569
1569
1570
let mut extra = mlua_expect ! ( self . extra. lock( ) , "extra is poisoned" ) ;
1570
- extra. registered_userdata . insert ( TypeId :: of :: < T > ( ) , id) ;
1571
+ extra. registered_userdata . insert ( type_id , id) ;
1571
1572
extra. registered_userdata_mt . insert ( ptr) ;
1572
1573
1573
1574
Ok ( id)
@@ -1616,12 +1617,13 @@ impl Lua {
1616
1617
{
1617
1618
unsafe extern "C" fn call_callback ( state : * mut ffi:: lua_State ) -> c_int {
1618
1619
callback_error ( state, |nargs| {
1619
- let func =
1620
- get_meta_gc_userdata :: < Callback , Callback > ( state, ffi:: lua_upvalueindex ( 1 ) ) ;
1621
- let lua = get_gc_userdata :: < Lua > ( state, ffi:: lua_upvalueindex ( 2 ) ) ;
1622
- if func. is_null ( ) || lua. is_null ( ) {
1620
+ if ffi:: lua_type ( state, ffi:: lua_upvalueindex ( 1 ) ) == ffi:: LUA_TNIL
1621
+ || ffi:: lua_type ( state, ffi:: lua_upvalueindex ( 2 ) ) == ffi:: LUA_TNIL
1622
+ {
1623
1623
return Err ( Error :: CallbackDestructed ) ;
1624
1624
}
1625
+ let func = get_userdata :: < Callback > ( state, ffi:: lua_upvalueindex ( 1 ) ) ;
1626
+ let lua = get_userdata :: < Lua > ( state, ffi:: lua_upvalueindex ( 2 ) ) ;
1625
1627
1626
1628
if nargs < ffi:: LUA_MINSTACK {
1627
1629
check_stack ( state, ffi:: LUA_MINSTACK - nargs) ?;
@@ -1681,14 +1683,13 @@ impl Lua {
1681
1683
1682
1684
unsafe extern "C" fn call_callback ( state : * mut ffi:: lua_State ) -> c_int {
1683
1685
callback_error ( state, |nargs| {
1684
- let func = get_meta_gc_userdata :: < AsyncCallback , AsyncCallback > (
1685
- state,
1686
- ffi:: lua_upvalueindex ( 1 ) ,
1687
- ) ;
1688
- let lua = get_gc_userdata :: < Lua > ( state, ffi:: lua_upvalueindex ( 2 ) ) ;
1689
- if func. is_null ( ) || lua. is_null ( ) {
1686
+ if ffi:: lua_type ( state, ffi:: lua_upvalueindex ( 1 ) ) == ffi:: LUA_TNIL
1687
+ || ffi:: lua_type ( state, ffi:: lua_upvalueindex ( 2 ) ) == ffi:: LUA_TNIL
1688
+ {
1690
1689
return Err ( Error :: CallbackDestructed ) ;
1691
1690
}
1691
+ let func = get_userdata :: < AsyncCallback > ( state, ffi:: lua_upvalueindex ( 1 ) ) ;
1692
+ let lua = get_userdata :: < Lua > ( state, ffi:: lua_upvalueindex ( 2 ) ) ;
1692
1693
1693
1694
if nargs < ffi:: LUA_MINSTACK {
1694
1695
check_stack ( state, ffi:: LUA_MINSTACK - nargs) ?;
@@ -1715,14 +1716,16 @@ impl Lua {
1715
1716
1716
1717
unsafe extern "C" fn poll_future ( state : * mut ffi:: lua_State ) -> c_int {
1717
1718
callback_error ( state, |nargs| {
1718
- let fut = get_gc_userdata :: < LocalBoxFuture < Result < MultiValue > > > (
1719
+ if ffi:: lua_type ( state, ffi:: lua_upvalueindex ( 1 ) ) == ffi:: LUA_TNIL
1720
+ || ffi:: lua_type ( state, ffi:: lua_upvalueindex ( 2 ) ) == ffi:: LUA_TNIL
1721
+ {
1722
+ return Err ( Error :: CallbackDestructed ) ;
1723
+ }
1724
+ let fut = get_userdata :: < LocalBoxFuture < Result < MultiValue > > > (
1719
1725
state,
1720
1726
ffi:: lua_upvalueindex ( 1 ) ,
1721
1727
) ;
1722
- let lua = get_gc_userdata :: < Lua > ( state, ffi:: lua_upvalueindex ( 2 ) ) ;
1723
- if fut. is_null ( ) || lua. is_null ( ) {
1724
- return Err ( Error :: CallbackDestructed ) ;
1725
- }
1728
+ let lua = get_userdata :: < Lua > ( state, ffi:: lua_upvalueindex ( 2 ) ) ;
1726
1729
1727
1730
if nargs < ffi:: LUA_MINSTACK {
1728
1731
check_stack ( state, ffi:: LUA_MINSTACK - nargs) ?;
@@ -1791,7 +1794,7 @@ impl Lua {
1791
1794
self . load (
1792
1795
r#"
1793
1796
poll = get_poll(...)
1794
- local poll = poll
1797
+ local poll, yield, unpack = poll, yield, unpack
1795
1798
while true do
1796
1799
ready, res = poll()
1797
1800
if ready then
0 commit comments