From 418d80b0e8e4fda82ac12a99f0a4037ab6328466 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 14 Jan 2015 00:25:25 +0000 Subject: [PATCH] Lua - Memory library - simplify some code --- .../lua/EmuLuaLibrary.Memory.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Memory.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Memory.cs index 4a4262fe9a..cc06bb45b1 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Memory.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Memory.cs @@ -10,7 +10,9 @@ namespace BizHawk.Client.Common [Description("These functions behavior identically to the mainmemory functions but the user can set the memory domain to read and write from. The default domain is main memory. Use getcurrentmemorydomain(), and setcurrentmemorydomain() to control which domain is used. Each core has its own set of valid memory domains. Use getmemorydomainlist() to get a list of memory domains for the current core loaded.")] public sealed class MemoryLuaLibrary : LuaMemoryBase { - private int _currentMemoryDomain; // Main memory by default probably (index 0 is currently always main memory but may never be) + //private int _currentMemoryDomain; // Main memory by default probably (index 0 is currently always main memory but may never be) + + private MemoryDomain _currentMemoryDomain; public MemoryLuaLibrary(Lua lua) : base(lua) @@ -18,7 +20,7 @@ namespace BizHawk.Client.Common if (MemoryDomainCore != null) { var domains = MemoryDomainCore.MemoryDomains; - _currentMemoryDomain = domains.IndexOf(domains.MainMemory); + _currentMemoryDomain = domains.MainMemory; } } @@ -28,7 +30,7 @@ namespace BizHawk.Client.Common if (MemoryDomainCore != null) { var domains = MemoryDomainCore.MemoryDomains; - _currentMemoryDomain = domains.IndexOf(domains.MainMemory); + _currentMemoryDomain = domains.MainMemory; } } @@ -40,7 +42,7 @@ namespace BizHawk.Client.Common { if (MemoryDomainCore != null) { - return MemoryDomainCore.MemoryDomains[_currentMemoryDomain]; + return _currentMemoryDomain; } else { @@ -93,13 +95,23 @@ namespace BizHawk.Client.Common )] public bool UseMemoryDomain(string domain) { - for (var i = 0; i < DomainList.Count; i++) + try { - if (DomainList[i].Name == domain) + if (DomainList[domain] != null) { - _currentMemoryDomain = i; + _currentMemoryDomain = DomainList[domain]; return true; } + else + { + Log(string.Format("Unable to find domain: ", domain)); + return false; + } + + } + catch // Just in case + { + Log(string.Format("Unable to find domain: ", domain)); } return false;