refactor LuaHelper into an extension method class, and some nitpick cleanups
This commit is contained in:
parent
8bb9cee9c2
commit
d955c468db
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class APISubsetContainer : IApiContainer
|
||||
public class ApiSubsetContainer : IApiContainer
|
||||
{
|
||||
public Dictionary<Type, IExternalApi> Libraries { get; set; }
|
||||
|
||||
|
@ -17,7 +17,7 @@ namespace BizHawk.Client.Common
|
|||
public ISql Sql => (ISql) Libraries[typeof(SqlApi)];
|
||||
public IUserData UserData => (IUserData) Libraries[typeof(UserDataApi)];
|
||||
|
||||
public APISubsetContainer(Dictionary<Type, IExternalApi> libs)
|
||||
public ApiSubsetContainer(Dictionary<Type, IExternalApi> libs)
|
||||
{
|
||||
Libraries = libs;
|
||||
}
|
||||
|
|
|
@ -4,13 +4,13 @@ using NLua;
|
|||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
/// <summary>Extends <see cref="LuaLibraryBase"/> by including an <see cref="APISubsetContainer"/> for the library to delegate its calls through. Some APIs may not be delegated.</summary>
|
||||
/// <summary>Extends <see cref="LuaLibraryBase"/> by including an <see cref="ApiSubsetContainer"/> for the library to delegate its calls through. Some APIs may not be delegated.</summary>
|
||||
public abstract class DelegatingLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
protected DelegatingLuaLibrary(Lua lua) : base(lua) {}
|
||||
|
||||
protected DelegatingLuaLibrary(Lua lua, Action<string> logOutputCallback) : base(lua, logOutputCallback) {}
|
||||
|
||||
public APISubsetContainer APIs { protected get; set; }
|
||||
public ApiSubsetContainer APIs { protected get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,10 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
return MemoryDomainCore.MainMemory;
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = $"Error: {Emulator.Attributes().CoreName} does not implement memory domains";
|
||||
Log(error);
|
||||
throw new NotImplementedException(error);
|
||||
}
|
||||
|
||||
var error = $"Error: {Emulator.Attributes().CoreName} does not implement memory domains";
|
||||
Log(error);
|
||||
throw new NotImplementedException(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ using NLua;
|
|||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public static class LuaHelper
|
||||
public static class LuaExtensions
|
||||
{
|
||||
public static LuaTable ToLuaTable(Lua lua, object obj)
|
||||
public static LuaTable TableFromObject(this Lua lua, object obj)
|
||||
{
|
||||
var table = lua.NewTable();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ using BizHawk.Client.Common;
|
|||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public sealed class ApiContainer : APISubsetContainer
|
||||
public sealed class ApiContainer : ApiSubsetContainer
|
||||
{
|
||||
public IComm Comm => (IComm) Libraries[typeof(CommApi)];
|
||||
public IGui Gui => (IGui) Libraries[typeof(GuiApi)];
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
using NLua;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Client.Common;
|
||||
using System.Threading;
|
||||
|
@ -23,15 +21,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
[RequiredService]
|
||||
private IVideoProvider VideoProvider { get; set; }
|
||||
|
||||
private readonly Dictionary<int, string> _filterMappings = new Dictionary<int, string>
|
||||
{
|
||||
{ 0, "None" },
|
||||
{ 1, "x2SAI" },
|
||||
{ 2, "SuperX2SAI" },
|
||||
{ 3, "SuperEagle" },
|
||||
{ 4, "Scanlines" },
|
||||
};
|
||||
|
||||
public EmuHawkLuaLibrary(Lua lua)
|
||||
: base(lua) { }
|
||||
|
||||
|
@ -445,7 +434,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public LuaTable GetTool(string name)
|
||||
{
|
||||
var selectedTool = APIs.Tool.GetTool(name);
|
||||
return selectedTool == null ? null : LuaHelper.ToLuaTable(Lua, selectedTool);
|
||||
return selectedTool == null ? null : Lua.TableFromObject(selectedTool);
|
||||
}
|
||||
|
||||
[LuaMethodExample("local nlclicre = client.createinstance( \"objectname\" );")]
|
||||
|
@ -453,7 +442,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public LuaTable CreateInstance(string name)
|
||||
{
|
||||
var instance = APIs.Tool.GetTool(name);
|
||||
return instance == null ? null : LuaHelper.ToLuaTable(Lua, instance);
|
||||
return instance == null ? null : Lua.TableFromObject(instance);
|
||||
}
|
||||
|
||||
[LuaMethodExample("client.displaymessages( true );")]
|
||||
|
|
|
@ -711,7 +711,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
var canvas = new LuaCanvas(width, height, x, y);
|
||||
canvas.Show();
|
||||
return LuaHelper.ToLuaTable(Lua, canvas);
|
||||
return Lua.TableFromObject(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/PreferQualifiedReference/@EntryValue">False</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AF/@EntryIndexedValue">AF</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AP/@EntryIndexedValue">API</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ARGB/@EntryIndexedValue">ARGB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AV/@EntryIndexedValue">AV</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BG/@EntryIndexedValue">BG</s:String>
|
||||
|
|
Loading…
Reference in New Issue