lua - convert memory libraries to use service injection

This commit is contained in:
adelikat 2015-01-01 20:19:20 +00:00
parent b6e33d010a
commit 01019686cf
3 changed files with 19 additions and 13 deletions

View File

@ -22,13 +22,13 @@ namespace BizHawk.Client.Common
{ {
get get
{ {
if (Global.Emulator.HasMemoryDomains()) if (MemoryDomainCore != null)
{ {
return Global.Emulator.AsMemoryDomains().MemoryDomains.MainMemory; return MemoryDomainCore.MemoryDomains.MainMemory;
} }
else else
{ {
var error = string.Format("Error: {0} does not implement memory domains", Global.Emulator.Attributes().CoreName); var error = string.Format("Error: {0} does not implement memory domains", Emulator.Attributes().CoreName);
Log(error); Log(error);
throw new NotImplementedException(error); throw new NotImplementedException(error);
} }

View File

@ -15,9 +15,9 @@ namespace BizHawk.Client.Common
public MemoryLuaLibrary(Lua lua) public MemoryLuaLibrary(Lua lua)
: base(lua) : base(lua)
{ {
if (Global.Emulator.HasMemoryDomains()) if (MemoryDomainCore != null)
{ {
var domains = Global.Emulator.AsMemoryDomains().MemoryDomains; var domains = MemoryDomainCore.MemoryDomains;
_currentMemoryDomain = domains.IndexOf(domains.MainMemory); _currentMemoryDomain = domains.IndexOf(domains.MainMemory);
} }
} }
@ -25,9 +25,9 @@ namespace BizHawk.Client.Common
public MemoryLuaLibrary(Lua lua, Action<string> logOutputCallback) public MemoryLuaLibrary(Lua lua, Action<string> logOutputCallback)
: base(lua, logOutputCallback) : base(lua, logOutputCallback)
{ {
if (Global.Emulator.HasMemoryDomains()) if (MemoryDomainCore != null)
{ {
var domains = Global.Emulator.AsMemoryDomains().MemoryDomains; var domains = MemoryDomainCore.MemoryDomains;
_currentMemoryDomain = domains.IndexOf(domains.MainMemory); _currentMemoryDomain = domains.IndexOf(domains.MainMemory);
} }
} }
@ -38,13 +38,13 @@ namespace BizHawk.Client.Common
{ {
get get
{ {
if (Global.Emulator.HasMemoryDomains()) if (MemoryDomainCore != null)
{ {
return Global.Emulator.AsMemoryDomains().MemoryDomains[_currentMemoryDomain]; return MemoryDomainCore.MemoryDomains[_currentMemoryDomain];
} }
else else
{ {
var error = string.Format("Error: {0} does not implement memory domains", Global.Emulator.Attributes().CoreName); var error = string.Format("Error: {0} does not implement memory domains", Emulator.Attributes().CoreName);
Log(error); Log(error);
throw new NotImplementedException(error); throw new NotImplementedException(error);
} }

View File

@ -10,6 +10,12 @@ namespace BizHawk.Client.Common
/// </summary> /// </summary>
public abstract class LuaMemoryBase : LuaLibraryBase public abstract class LuaMemoryBase : LuaLibraryBase
{ {
[RequiredService]
protected IEmulator Emulator { get; set; }
[OptionalService]
protected IMemoryDomains MemoryDomainCore { get; set; }
public LuaMemoryBase(Lua lua) public LuaMemoryBase(Lua lua)
: base(lua) { } : base(lua) { }
@ -22,13 +28,13 @@ namespace BizHawk.Client.Common
{ {
get get
{ {
if (Global.Emulator.HasMemoryDomains()) if (MemoryDomainCore != null)
{ {
return Global.Emulator.AsMemoryDomains().MemoryDomains; return MemoryDomainCore.MemoryDomains;
} }
else else
{ {
var error = string.Format("Error: {0} does not implement memory domains", Global.Emulator.Attributes().CoreName); var error = string.Format("Error: {0} does not implement memory domains", Emulator.Attributes().CoreName);
Log(error); Log(error);
throw new NotImplementedException(error); throw new NotImplementedException(error);
} }