Lua - Memory library - simplify some code
This commit is contained in:
parent
9c8bb5ff1f
commit
418d80b0e8
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue