@@ -880,6 +880,11 @@ internal LuaTable GetTable(LuaState luaState, int index)
880880 // Before create new tables, check if there is any finalized object to clean.
881881 CleanFinalizedReferences ( luaState ) ;
882882
883+ if ( luaState . Type ( index ) != LuaType . Table )
884+ {
885+ return null ;
886+ }
887+
883888 luaState . PushCopy ( index ) ;
884889 var reference = luaState . Ref ( LuaRegistry . Index ) ;
885890 return reference == - 1 ? null : new LuaTable ( reference , interpreter ) ;
@@ -893,6 +898,11 @@ internal LuaThread GetThread(LuaState luaState, int index)
893898 // Before create new tables, check if there is any finalized object to clean.
894899 CleanFinalizedReferences ( luaState ) ;
895900
901+ if ( luaState . Type ( index ) != LuaType . Thread )
902+ {
903+ return null ;
904+ }
905+
896906 luaState . PushCopy ( index ) ;
897907 var reference = luaState . Ref ( LuaRegistry . Index ) ;
898908 return reference == - 1 ? null : new LuaThread ( reference , interpreter ) ;
@@ -906,6 +916,11 @@ internal LuaUserData GetUserData(LuaState luaState, int index)
906916 // Before create new tables, check if there is any finalized object to clean.
907917 CleanFinalizedReferences ( luaState ) ;
908918
919+ if ( luaState . Type ( index ) != LuaType . UserData )
920+ {
921+ return null ;
922+ }
923+
909924 luaState . PushCopy ( index ) ;
910925 var reference = luaState . Ref ( LuaRegistry . Index ) ;
911926 return reference == - 1 ? null : new LuaUserData ( reference , interpreter ) ;
@@ -919,6 +934,11 @@ internal LuaFunction GetFunction(LuaState luaState, int index)
919934 // Before create new tables, check if there is any finalized object to clean.
920935 CleanFinalizedReferences ( luaState ) ;
921936
937+ if ( luaState . Type ( index ) != LuaType . Function )
938+ {
939+ return null ;
940+ }
941+
922942 luaState . PushCopy ( index ) ;
923943 var reference = luaState . Ref ( LuaRegistry . Index ) ;
924944 return reference == - 1 ? null : new LuaFunction ( reference , interpreter ) ;
0 commit comments