diff --git a/src/BizHawk.Client.Common/lua/LuaLibraries.cs b/src/BizHawk.Client.Common/lua/LuaLibraries.cs index 8bc1ec5a31..ee29505b11 100644 --- a/src/BizHawk.Client.Common/lua/LuaLibraries.cs +++ b/src/BizHawk.Client.Common/lua/LuaLibraries.cs @@ -47,7 +47,6 @@ namespace BizHawk.Client.Common public abstract (bool WaitForFrame, bool Terminated) ResumeScript(LuaFile lf); public abstract void SpawnAndSetFileThread(string pathToLoad, LuaFile lf); public abstract void StartLuaDrawing(); - public abstract void WindowClosed(IntPtr handle); public abstract void RunScheduledDisposes(); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs index 3fe0ef2a04..368a91bf37 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs @@ -23,14 +23,8 @@ namespace BizHawk.Client.EmuHawk public void WindowClosed(IntPtr handle) { - foreach (var form in _luaForms) - { - if (form.Handle == handle) - { - _luaForms.Remove(form); - return; - } - } + var form = _luaForms.FirstOrDefault(form => form.Handle == handle); + if (form != null) _luaForms.Remove(form); } private LuaWinform GetForm(int formHandle) @@ -352,7 +346,7 @@ namespace BizHawk.Client.EmuHawk "newform", "creates a new default dialog, if both width and height are specified it will create a dialog of the specified size. If title is specified it will be the caption of the dialog, else the dialog caption will be 'Lua Dialog'. The function will return an int representing the handle of the dialog created.")] public int NewForm(int? width = null, int? height = null, string title = null, LuaFunction onClose = null) { - var form = new LuaWinform(CurrentFile, _luaLibsImpl); + var form = new LuaWinform(CurrentFile, WindowClosed); _luaForms.Add(form); if (width.HasValue && height.HasValue) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaWinform.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaWinform.cs index 33694e4ca3..9118174ad5 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaWinform.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaWinform.cs @@ -10,18 +10,16 @@ namespace BizHawk.Client.EmuHawk { public List ControlEvents { get; } = new List(); - private readonly LuaLibraries _luaImp; private readonly string _currentDirectory = Environment.CurrentDirectory; private readonly LuaFile _ownerFile; - public LuaWinform(LuaFile ownerFile, LuaLibraries luaImp) + public LuaWinform(LuaFile ownerFile, Action formsWindowClosedCallback) { _ownerFile = ownerFile; - _luaImp = luaImp; InitializeComponent(); Icon = Properties.Resources.TextDocIcon; StartPosition = FormStartPosition.CenterParent; - Closing += (o, e) => { _luaImp.WindowClosed(Handle); }; + Closing += (o, e) => formsWindowClosedCallback(Handle); } public void DoLuaEvent(IntPtr handle) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/UnixLuaLibraries.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/UnixLuaLibraries.cs index 63dd701b7d..4f78e295bb 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/UnixLuaLibraries.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/UnixLuaLibraries.cs @@ -52,9 +52,6 @@ namespace BizHawk.Client.EmuHawk public override void StartLuaDrawing() { } - public override void WindowClosed(IntPtr handle) - { - } public override void RunScheduledDisposes() { diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs index 303320800e..5671fa1469 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs @@ -150,11 +150,6 @@ namespace BizHawk.Client.EmuHawk public override LuaFunctionList RegisteredFunctions => EventsLibrary.RegisteredFunctions; - public override void WindowClosed(IntPtr handle) - { - FormsLibrary.WindowClosed(handle); - } - public override void CallSaveStateEvent(string name) { EventsLibrary.CallSaveStateEvent(name);