Lua - Memory library - simplify some code

This commit is contained in:
adelikat 2015-01-14 00:25:25 +00:00
parent 9c8bb5ff1f
commit 418d80b0e8
1 changed files with 19 additions and 7 deletions

View File

@ -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;