@@ -21,7 +21,7 @@ use crate::string::String;
2121use crate :: table:: { Table , TablePairs } ;
2222use crate :: traits:: { FromLua , FromLuaMulti , IntoLua , IntoLuaMulti } ;
2323use crate :: types:: { MaybeSend , ValueRef } ;
24- use crate :: util:: { check_stack, get_userdata, take_userdata, StackGuard } ;
24+ use crate :: util:: { check_stack, get_userdata, push_string , take_userdata, StackGuard } ;
2525use crate :: value:: Value ;
2626
2727// Re-export for convenience
@@ -809,13 +809,10 @@ impl AnyUserData {
809809 lua. push_userdata_ref ( & self . 0 ) ?;
810810
811811 // Multiple (extra) user values are emulated by storing them in a table
812- protect_lua ! ( state, 1 , 1 , |state| {
813- if ffi:: lua_getuservalue( state, -1 ) != ffi:: LUA_TTABLE {
814- ffi:: lua_pushnil( state) ;
815- return ;
816- }
817- ffi:: lua_rawgeti( state, -1 , n as ffi:: lua_Integer) ;
818- } ) ?;
812+ if ffi:: lua_getuservalue ( state, -1 ) != ffi:: LUA_TTABLE {
813+ return V :: from_lua ( Value :: Nil , lua. lua ( ) ) ;
814+ }
815+ ffi:: lua_rawgeti ( state, -1 , n as ffi:: lua_Integer ) ;
819816
820817 V :: from_lua ( lua. pop_value ( ) , lua. lua ( ) )
821818 }
@@ -873,16 +870,13 @@ impl AnyUserData {
873870 lua. push_userdata_ref ( & self . 0 ) ?;
874871
875872 // Multiple (extra) user values are emulated by storing them in a table
876- protect_lua ! ( state, 1 , 1 , |state| {
877- if ffi:: lua_getuservalue( state, -1 ) != ffi:: LUA_TTABLE {
878- ffi:: lua_pushnil( state) ;
879- return ;
880- }
881- ffi:: lua_pushlstring( state, name. as_ptr( ) as * const c_char, name. len( ) ) ;
882- ffi:: lua_rawget( state, -2 ) ;
883- } ) ?;
873+ if ffi:: lua_getuservalue ( state, -1 ) != ffi:: LUA_TTABLE {
874+ return V :: from_lua ( Value :: Nil , lua. lua ( ) ) ;
875+ }
876+ push_string ( state, name. as_bytes ( ) , !lua. unlikely_memory_error ( ) ) ?;
877+ ffi:: lua_rawget ( state, -2 ) ;
884878
885- V :: from_lua ( lua . pop_value ( ) , lua. lua ( ) )
879+ V :: from_stack ( - 1 , & lua)
886880 }
887881 }
888882
0 commit comments