From d955c468db1d7d84a8113245d9ab8c61c7cb9213 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 15 Dec 2019 09:05:33 -0600 Subject: [PATCH] refactor LuaHelper into an extension method class, and some nitpick cleanups --- BizHawk.Client.Common/Api/APISubsetContainer.cs | 4 ++-- BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs | 4 ++-- .../lua/EmuLuaLibrary.MainMemory.cs | 10 ++++------ BizHawk.Client.Common/lua/LuaHelper.cs | 4 ++-- BizHawk.Client.EmuHawk/Api/ApiContainer.cs | 2 +- .../tools/Lua/Libraries/EmuLuaLibrary.Client.cs | 15 ++------------- .../tools/Lua/Libraries/EmuLuaLibrary.Gui.cs | 2 +- BizHawk.sln.DotSettings | 1 + 8 files changed, 15 insertions(+), 27 deletions(-) diff --git a/BizHawk.Client.Common/Api/APISubsetContainer.cs b/BizHawk.Client.Common/Api/APISubsetContainer.cs index e911754846..0fc261c6a0 100644 --- a/BizHawk.Client.Common/Api/APISubsetContainer.cs +++ b/BizHawk.Client.Common/Api/APISubsetContainer.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace BizHawk.Client.Common { - public class APISubsetContainer : IApiContainer + public class ApiSubsetContainer : IApiContainer { public Dictionary 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 libs) + public ApiSubsetContainer(Dictionary libs) { Libraries = libs; } diff --git a/BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs b/BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs index 63789a1a22..dc921d6f44 100644 --- a/BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs +++ b/BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs @@ -4,13 +4,13 @@ using NLua; namespace BizHawk.Client.Common { - /// Extends by including an for the library to delegate its calls through. Some APIs may not be delegated. + /// Extends by including an for the library to delegate its calls through. Some APIs may not be delegated. public abstract class DelegatingLuaLibrary : LuaLibraryBase { protected DelegatingLuaLibrary(Lua lua) : base(lua) {} protected DelegatingLuaLibrary(Lua lua, Action logOutputCallback) : base(lua, logOutputCallback) {} - public APISubsetContainer APIs { protected get; set; } + public ApiSubsetContainer APIs { protected get; set; } } } diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.MainMemory.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.MainMemory.cs index 4b5d9e5a8d..e19e771f7b 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.MainMemory.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.MainMemory.cs @@ -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); } } diff --git a/BizHawk.Client.Common/lua/LuaHelper.cs b/BizHawk.Client.Common/lua/LuaHelper.cs index 2d04fcad95..1eb74cff21 100644 --- a/BizHawk.Client.Common/lua/LuaHelper.cs +++ b/BizHawk.Client.Common/lua/LuaHelper.cs @@ -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(); diff --git a/BizHawk.Client.EmuHawk/Api/ApiContainer.cs b/BizHawk.Client.EmuHawk/Api/ApiContainer.cs index 39437d60d2..7e981d87f2 100644 --- a/BizHawk.Client.EmuHawk/Api/ApiContainer.cs +++ b/BizHawk.Client.EmuHawk/Api/ApiContainer.cs @@ -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)]; diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs index 1949d4ce94..082a4256d3 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs @@ -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 _filterMappings = new Dictionary - { - { 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 );")] diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs index 176dd74552..e6cbe63beb 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs @@ -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); } } } diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index c34d6b748d..bb273a4635 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -66,6 +66,7 @@ False False AF + API ARGB AV BG