11using System ;
2- using System . Collections . Generic ;
32using System . IO ;
43using System . Runtime . CompilerServices ;
54using System . Runtime . InteropServices ;
@@ -30,14 +29,9 @@ public sealed unsafe partial class Lua
3029 /// <remarks>
3130 /// Subscribed event handlers must not throw any exceptions.
3231 /// </remarks>
33- public event EventHandler < LuaWarningEmittedEventArgs > WarningEmitted
34- {
35- add => ( _warningHandlers ??= new ( ) ) . Add ( value ) ;
36- remove => _warningHandlers ? . Remove ( value ) ;
37- }
32+ public event EventHandler < LuaWarningEmittedEventArgs > ? WarningEmitted ;
3833
3934 private MemoryStream ? _warningBuffer ;
40- private List < EventHandler < LuaWarningEmittedEventArgs > > ? _warningHandlers ;
4135
4236 [ UnmanagedCallersOnly ( CallConvs = new [ ] { typeof ( CallConvCdecl ) } ) ]
4337 private static void WarningHandler ( void * ud , byte * msg , int tocont )
@@ -50,7 +44,7 @@ private static void WarningHandler(void* ud, byte* msg, int tocont)
5044 return ;
5145 }
5246
53- if ( ! lua . EmitsWarnings || lua . _warningHandlers == null || lua . _warningHandlers . Count == 0 )
47+ if ( ! lua . EmitsWarnings || lua . WarningEmitted == null )
5448 {
5549 return ;
5650 }
@@ -79,10 +73,7 @@ private static void WarningHandler(void* ud, byte* msg, int tocont)
7973
8074 using ( message )
8175 {
82- foreach ( var handler in lua . _warningHandlers )
83- {
84- handler . Invoke ( lua , new LuaWarningEmittedEventArgs ( message ) ) ;
85- }
76+ lua . WarningEmitted ? . Invoke ( lua , new LuaWarningEmittedEventArgs ( message ) ) ;
8677 }
8778
8879 static void ProcessControlWarningMessage ( Lua lua , ReadOnlySpan < byte > controlMsg )
0 commit comments