From 9a24539c100af2ce0882716df736f4db43c09516 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 31 May 2014 14:29:27 +0000 Subject: [PATCH] Lua - catch NotImplementedException on emu.getregister(s) and warn the user that this particular core doesn't implement this feature yet. Also, put IEmulator extensions in their own namespace --- BizHawk.Client.Common/PathManager.cs | 1 + .../lua/EmuLuaLibrary.Emu.cs | 30 ++++++++++++++++--- BizHawk.Client.EmuHawk/MainForm.cs | 2 ++ BizHawk.Emulation.Common/Extensions.cs | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/BizHawk.Client.Common/PathManager.cs b/BizHawk.Client.Common/PathManager.cs index 12568a1df3..a5fd47f87d 100644 --- a/BizHawk.Client.Common/PathManager.cs +++ b/BizHawk.Client.Common/PathManager.cs @@ -4,6 +4,7 @@ using System.IO; using System.Reflection; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Cores.Nintendo.SNES; namespace BizHawk.Client.Common diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs index abb7d0424d..724d5bd702 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Cores.PCEngine; using BizHawk.Emulation.Cores.Sega.MasterSystem; @@ -57,9 +58,20 @@ namespace BizHawk.Client.Common "getregister", "returns the value of a cpu register or flag specified by name. For a complete list of possible registers or flags for a given core, use getregisters" )] - public static int GetRegister(string name) + public int GetRegister(string name) { - return Global.Emulator.GetCpuFlagsAndRegisters().FirstOrDefault(x => x.Key == name).Value; + try + { + return Global.Emulator.GetCpuFlagsAndRegisters().FirstOrDefault(x => x.Key == name).Value; + } + catch (NotImplementedException) + { + + Log(string.Format( + "Error: {0} does not yet implement getregister()", + Global.Emulator.Attributes().CoreName)); + return 0; + } } [LuaMethodAttributes( @@ -69,9 +81,19 @@ namespace BizHawk.Client.Common public LuaTable GetRegisters() { var table = Lua.NewTable(); - foreach (var kvp in Global.Emulator.GetCpuFlagsAndRegisters()) + + try { - table[kvp.Key] = kvp.Value; + foreach (var kvp in Global.Emulator.GetCpuFlagsAndRegisters()) + { + table[kvp.Key] = kvp.Value; + } + } + catch (NotImplementedException) + { + Log(string.Format( + "Error: {0} does not yet implement getregisters()", + Global.Emulator.Attributes().CoreName)); } return table; diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 41a25afb14..88df830903 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -7,9 +7,11 @@ using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; + using BizHawk.Client.Common; using BizHawk.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Cores.Atari.Atari2600; using BizHawk.Emulation.Cores.Atari.Atari7800; using BizHawk.Emulation.Cores.Calculators; diff --git a/BizHawk.Emulation.Common/Extensions.cs b/BizHawk.Emulation.Common/Extensions.cs index d1457fed2b..cbb005ce29 100644 --- a/BizHawk.Emulation.Common/Extensions.cs +++ b/BizHawk.Emulation.Common/Extensions.cs @@ -1,6 +1,6 @@ using System; -namespace BizHawk.Emulation.Common +namespace BizHawk.Emulation.Common.IEmulatorExtensions { public static class Extensions {