diff --git a/src/BizHawk.Client.Common/lua/ILuaLibraries.cs b/src/BizHawk.Client.Common/lua/ILuaLibraries.cs index af3643fa79..06d04c7466 100644 --- a/src/BizHawk.Client.Common/lua/ILuaLibraries.cs +++ b/src/BizHawk.Client.Common/lua/ILuaLibraries.cs @@ -53,5 +53,9 @@ namespace BizHawk.Client.Common void ExecuteString(string command); (bool WaitForFrame, bool Terminated) ResumeScript(LuaFile lf); + + void EnableLuaFile(LuaFile item); + + void DisableLuaScript(LuaFile file); } } \ No newline at end of file diff --git a/src/BizHawk.Client.Common/lua/LuaLibrariesBase.cs b/src/BizHawk.Client.Common/lua/LuaLibrariesBase.cs index a718ad6576..099ef41291 100644 --- a/src/BizHawk.Client.Common/lua/LuaLibrariesBase.cs +++ b/src/BizHawk.Client.Common/lua/LuaLibrariesBase.cs @@ -352,5 +352,33 @@ namespace BizHawk.Client.Common { _currThread.Yield(); } + + public void DisableLuaScript(LuaFile file) + { + if (file.IsSeparator) return; + + file.State = LuaFile.RunState.Disabled; + + if (file.Thread is not null) + { + CallExitEvent(file); + RegisteredFunctions.RemoveForFile(file, _mainFormApi.Emulator); + file.Stop(); + } + } + + public void EnableLuaFile(LuaFile item) + { + LuaSandbox.Sandbox(null, () => + { + SpawnAndSetFileThread(item.Path, item); + LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(item.Path)); + }, () => + { + item.State = LuaFile.RunState.Disabled; + }); + + // there used to be a call here which did a redraw of the Gui/OSD, which included a call to `Tools.UpdateToolsAfter` --yoshi + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 1b4925c0d8..9b2ef3505a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -204,7 +204,7 @@ namespace BizHawk.Client.EmuHawk // we don't use runningScripts here as the other scripts need to be stopped too foreach (var file in LuaImp.ScriptList) { - DisableLuaScript(file); + LuaImp.DisableLuaScript(file); } } @@ -368,7 +368,7 @@ namespace BizHawk.Client.EmuHawk { if (!item.IsSeparator) { - DisableLuaScript(item); + LuaImp.DisableLuaScript(item); RemoveFileWatcher(item); } LuaImp.ScriptList.Remove(item); @@ -899,16 +899,7 @@ namespace BizHawk.Client.EmuHawk { try { - LuaSandbox.Sandbox(null, () => - { - LuaImp.SpawnAndSetFileThread(item.Path, item); - LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(item.Path)); - }, () => - { - item.State = LuaFile.RunState.Disabled; - }); - - // there used to be a call here which did a redraw of the Gui/OSD, which included a call to `Tools.UpdateToolsAfter` --yoshi + LuaImp.EnableLuaFile(item); } catch (IOException) { @@ -1064,7 +1055,7 @@ namespace BizHawk.Client.EmuHawk { foreach (var file in LuaImp.ScriptList) { - DisableLuaScript(file); + LuaImp.DisableLuaScript(file); } UpdateDialog(); } @@ -1497,25 +1488,11 @@ namespace BizHawk.Client.EmuHawk } else if (!file.Enabled && file.Thread is not null) { - DisableLuaScript(file); + LuaImp.DisableLuaScript(file); // there used to be a call here which did a redraw of the Gui/OSD, which included a call to `Tools.UpdateToolsAfter` --yoshi } } - private void DisableLuaScript(LuaFile file) - { - if (file.IsSeparator) return; - - file.State = LuaFile.RunState.Disabled; - - if (file.Thread is not null) - { - LuaImp.CallExitEvent(file); - LuaImp.RegisteredFunctions.RemoveForFile(file, Emulator); - file.Stop(); - } - } - private void RefreshLuaScript(LuaFile file) { ToggleLuaScript(file);