From 0effd435f6ab5f098f094e6073de07d991262b49 Mon Sep 17 00:00:00 2001 From: kalimag Date: Sun, 27 Nov 2022 19:53:56 +0100 Subject: [PATCH] Fix issues when opening same Lua script multiple times --- .../tools/Lua/LuaConsole.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 4ae5c36fbf..8446b9b5c7 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -299,23 +299,13 @@ namespace BizHawk.Client.EmuHawk var processedPath = Config.PathEntries.TryMakeRelative(path); - var alreadyInSession = luaLibsImpl.ScriptList.Any(t => processedPath == t.Path); - if (alreadyInSession) + var alreadyLoadedFile = luaLibsImpl.ScriptList.FirstOrDefault(t => processedPath == t.Path); + if (alreadyLoadedFile is not null) { - foreach (var file in luaLibsImpl.ScriptList - .Where(file => processedPath == file.Path - && file.Enabled == false - && !Settings.DisableLuaScriptsOnLoad)) + if (!alreadyLoadedFile.Enabled && !Settings.DisableLuaScriptsOnLoad) { - if (file.Thread is not null) - { - file.Toggle(); - } - - break; + ToggleLuaScript(alreadyLoadedFile); } - - RunLuaScripts(); } else {