From 339994c5a72310b79e4f9eb519b683a18e12c6b1 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Tue, 6 Dec 2022 09:46:12 -0800 Subject: [PATCH] change these to using var --- .../tools/Lua/Win32LuaLibraries.cs | 131 +++++++++--------- 1 file changed, 62 insertions(+), 69 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs index eb6a632018..f900f55b5f 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs @@ -185,91 +185,86 @@ namespace BizHawk.Client.EmuHawk public void CallSaveStateEvent(string name) { - using (GuiAPI.ThisIsTheLuaAutoUnlockHack()) + using var luaAutoUnlockHack = GuiAPI.ThisIsTheLuaAutoUnlockHack(); + + try { - try + foreach (var lf in RegisteredFunctions.Where(static l => l.Event == NamedLuaFunction.EVENT_TYPE_SAVESTATE).ToList()) { - foreach (var lf in RegisteredFunctions.Where(static l => l.Event == NamedLuaFunction.EVENT_TYPE_SAVESTATE).ToList()) - { - lf.Call(name); - } - } - catch (Exception e) - { - LogToLuaConsole($"error running function attached by lua function event.onsavestate\nError message: {e.Message}"); + lf.Call(name); } } + catch (Exception e) + { + LogToLuaConsole($"error running function attached by lua function event.onsavestate\nError message: {e.Message}"); + } } public void CallLoadStateEvent(string name) { - using (GuiAPI.ThisIsTheLuaAutoUnlockHack()) + using var luaAutoUnlockHack = GuiAPI.ThisIsTheLuaAutoUnlockHack(); + + try { - try + foreach (var lf in RegisteredFunctions.Where(static l => l.Event == NamedLuaFunction.EVENT_TYPE_LOADSTATE).ToList()) { - foreach (var lf in RegisteredFunctions.Where(static l => l.Event == NamedLuaFunction.EVENT_TYPE_LOADSTATE).ToList()) - { - lf.Call(name); - } - } - catch (Exception e) - { - LogToLuaConsole($"error running function attached by lua function event.onloadstate\nError message: {e.Message}"); + lf.Call(name); } } + catch (Exception e) + { + LogToLuaConsole($"error running function attached by lua function event.onloadstate\nError message: {e.Message}"); + } } public void CallFrameBeforeEvent() { if (IsUpdateSupressed) return; - using (GuiAPI.ThisIsTheLuaAutoUnlockHack()) + using var luaAutoUnlockHack = GuiAPI.ThisIsTheLuaAutoUnlockHack(); + + try { - try + foreach (var lf in RegisteredFunctions.Where(static l => l.Event == NamedLuaFunction.EVENT_TYPE_PREFRAME).ToList()) { - foreach (var lf in RegisteredFunctions.Where(static l => l.Event == NamedLuaFunction.EVENT_TYPE_PREFRAME).ToList()) - { - lf.Call(); - } - } - catch (Exception e) - { - LogToLuaConsole($"error running function attached by lua function event.onframestart\nError message: {e.Message}"); + lf.Call(); } } + catch (Exception e) + { + LogToLuaConsole($"error running function attached by lua function event.onframestart\nError message: {e.Message}"); + } } public void CallFrameAfterEvent() { if (IsUpdateSupressed) return; - using (GuiAPI.ThisIsTheLuaAutoUnlockHack()) + using var luaAutoUnlockHack = GuiAPI.ThisIsTheLuaAutoUnlockHack(); + + try { - try + foreach (var lf in RegisteredFunctions.Where(static l => l.Event == NamedLuaFunction.EVENT_TYPE_POSTFRAME).ToList()) { - foreach (var lf in RegisteredFunctions.Where(static l => l.Event == NamedLuaFunction.EVENT_TYPE_POSTFRAME).ToList()) - { - lf.Call(); - } - } - catch (Exception e) - { - LogToLuaConsole($"error running function attached by lua function event.onframeend\nError message: {e.Message}"); + lf.Call(); } } + catch (Exception e) + { + LogToLuaConsole($"error running function attached by lua function event.onframeend\nError message: {e.Message}"); + } } public void CallExitEvent(LuaFile lf) { - using (GuiAPI.ThisIsTheLuaAutoUnlockHack()) + using var luaAutoUnlockHack = GuiAPI.ThisIsTheLuaAutoUnlockHack(); + + foreach (var exitCallback in RegisteredFunctions + .Where(l => l.Event == NamedLuaFunction.EVENT_TYPE_ENGINESTOP + && (l.LuaFile.Path == lf.Path || ReferenceEquals(l.LuaFile.Thread, lf.Thread))) + .ToList()) { - foreach (var exitCallback in RegisteredFunctions - .Where(l => l.Event == NamedLuaFunction.EVENT_TYPE_ENGINESTOP - && (l.LuaFile.Path == lf.Path || ReferenceEquals(l.LuaFile.Thread, lf.Thread))) - .ToList()) - { - exitCallback.Call(); - } + exitCallback.Call(); } } @@ -327,31 +322,29 @@ namespace BizHawk.Client.EmuHawk public (bool WaitForFrame, bool Terminated) ResumeScript(LuaFile lf) { - using (GuiAPI.ThisIsTheLuaAutoUnlockHack()) + _currThread = lf.Thread; + using var luaAutoUnlockHack = GuiAPI.ThisIsTheLuaAutoUnlockHack(); + + try { - _currThread = lf.Thread; + LuaLibraryBase.SetCurrentThread(lf); - try + var execResult = _currThread.Resume(); + + _currThread = null; + var result = execResult switch { - LuaLibraryBase.SetCurrentThread(lf); + KeraLua.LuaStatus.OK => (WaitForFrame: false, Terminated: true), + KeraLua.LuaStatus.Yield => (WaitForFrame: FrameAdvanceRequested, Terminated: false), + _ => throw new InvalidOperationException($"{nameof(_currThread.Resume)}() returned {execResult}?") + }; - var execResult = _currThread.Resume(); - - _currThread = null; - var result = execResult switch - { - KeraLua.LuaStatus.OK => (WaitForFrame: false, Terminated: true), - KeraLua.LuaStatus.Yield => (WaitForFrame: FrameAdvanceRequested, Terminated: false), - _ => throw new InvalidOperationException($"{nameof(_currThread.Resume)}() returned {execResult}?") - }; - - FrameAdvanceRequested = false; - return result; - } - finally - { - LuaLibraryBase.ClearCurrentThread(); - } + FrameAdvanceRequested = false; + return result; + } + finally + { + LuaLibraryBase.ClearCurrentThread(); } }