From 76f03a950869061bfeae8dd87754eacd99941ecd Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 3 Dec 2020 20:33:51 +1000 Subject: [PATCH] Merge DelegatingLuaLibrary into LuaLibraryBase --- .../lua/CommonLibs/ClientLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/CommLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/EmulationLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/GameInfoLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/GuiLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/InputLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/JoypadLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/MemoryLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/MemorySavestateLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/MovieLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/SQLiteLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/SaveStateLuaLibrary.cs | 6 +++--- .../lua/CommonLibs/UserDataLuaLibrary.cs | 6 +++--- .../lua/DelegatingLuaLibrary.cs | 15 --------------- .../lua/LuaHelperLibs/BitLuaLibrary.cs | 4 ++-- .../lua/LuaHelperLibs/EventsLuaLibrary.cs | 4 ++-- .../lua/LuaHelperLibs/GenesisLuaLibrary.cs | 6 +++--- .../lua/LuaHelperLibs/MainMemoryLuaLibrary.cs | 6 +++--- .../lua/LuaHelperLibs/NESLuaLibrary.cs | 6 +++--- .../lua/LuaHelperLibs/SNESLuaLibrary.cs | 6 +++--- .../lua/LuaHelperLibs/StringLuaLibrary.cs | 4 ++-- src/BizHawk.Client.Common/lua/LuaLibraryBase.cs | 5 ++++- .../tools/Lua/Libraries/ConsoleLuaLibrary.cs | 4 ++-- .../tools/Lua/Libraries/FormsLuaLibrary.cs | 4 ++-- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 4 ++-- .../tools/Lua/Win32LuaLibraries.cs | 4 +--- 26 files changed, 68 insertions(+), 82 deletions(-) delete mode 100644 src/BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs index e09623a5aa..bc26baed95 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs @@ -16,7 +16,7 @@ using NLua; namespace BizHawk.Client.Common { [Description("A library for manipulating the EmuHawk client UI")] - public sealed class ClientLuaLibrary : DelegatingLuaLibrary + public sealed class ClientLuaLibrary : LuaLibraryBase { [RequiredService] private IEmulator Emulator { get; set; } @@ -26,8 +26,8 @@ namespace BizHawk.Client.Common public IMainFormForApi MainForm { get; set; } - public ClientLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public ClientLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "client"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs index 88cc5425bb..f3b57e18ce 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs @@ -9,12 +9,12 @@ using NLua; namespace BizHawk.Client.Common { [Description("A library for communicating with other programs")] - public sealed class CommLuaLibrary : DelegatingLuaLibrary + public sealed class CommLuaLibrary : LuaLibraryBase { private readonly IDictionary _websockets = new Dictionary(); - public CommLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public CommLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "comm"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs index 6fcafef8d4..cfe6e20d8b 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/EmulationLuaLibrary.cs @@ -8,13 +8,13 @@ using NLua; namespace BizHawk.Client.Common { [Description("A library for interacting with the currently loaded emulator core")] - public sealed class EmulationLuaLibrary : DelegatingLuaLibrary + public sealed class EmulationLuaLibrary : LuaLibraryBase { public Action FrameAdvanceCallback { get; set; } public Action YieldCallback { get; set; } - public EmulationLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public EmulationLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "emu"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs index 7255f692d3..62fb87775c 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs @@ -5,10 +5,10 @@ using NLua; // ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { - public sealed class GameInfoLuaLibrary : DelegatingLuaLibrary + public sealed class GameInfoLuaLibrary : LuaLibraryBase { - public GameInfoLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public GameInfoLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "gameinfo"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/GuiLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/GuiLuaLibrary.cs index a2b83048a0..96ffae1e48 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/GuiLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/GuiLuaLibrary.cs @@ -5,12 +5,12 @@ using NLua; namespace BizHawk.Client.Common { - public sealed class GuiLuaLibrary : DelegatingLuaLibrary, IDisposable + public sealed class GuiLuaLibrary : LuaLibraryBase, IDisposable { public Func CreateLuaCanvasCallback { get; set; } - public GuiLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public GuiLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "gui"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/InputLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/InputLuaLibrary.cs index 9794e3b972..fd1dfae8c0 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/InputLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/InputLuaLibrary.cs @@ -4,10 +4,10 @@ using NLua; namespace BizHawk.Client.Common { - public sealed class InputLuaLibrary : DelegatingLuaLibrary + public sealed class InputLuaLibrary : LuaLibraryBase { - public InputLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public InputLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "input"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs index 1888d8f1c8..aedd617cde 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs @@ -6,10 +6,10 @@ using NLua; // ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { - public sealed class JoypadLuaLibrary : DelegatingLuaLibrary + public sealed class JoypadLuaLibrary : LuaLibraryBase { - public JoypadLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public JoypadLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "joypad"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs index 469064668b..e54fcca423 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs @@ -7,10 +7,10 @@ using NLua; 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 the system bus. Use getcurrentmemorydomain(), and usememorydomain() 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 : DelegatingLuaLibrary + public sealed class MemoryLuaLibrary : LuaLibraryBase { - public MemoryLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public MemoryLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "memory"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/MemorySavestateLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/MemorySavestateLuaLibrary.cs index d4f4255323..bc5565a65c 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/MemorySavestateLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/MemorySavestateLuaLibrary.cs @@ -5,10 +5,10 @@ using NLua; // ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { - public sealed class MemorySavestateLuaLibrary : DelegatingLuaLibrary + public sealed class MemorySavestateLuaLibrary : LuaLibraryBase { - public MemorySavestateLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public MemorySavestateLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "memorysavestate"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs index 9cb8b371de..537f3d03b7 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs @@ -5,10 +5,10 @@ using NLua; // ReSharper disable UnusedMember.Global namespace BizHawk.Client.Common { - public sealed class MovieLuaLibrary : DelegatingLuaLibrary + public sealed class MovieLuaLibrary : LuaLibraryBase { - public MovieLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public MovieLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "movie"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/SQLiteLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/SQLiteLuaLibrary.cs index f81cb3f0c9..c337025e7e 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/SQLiteLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/SQLiteLuaLibrary.cs @@ -8,10 +8,10 @@ using NLua; namespace BizHawk.Client.Common { [Description("A library for performing SQLite operations.")] - public sealed class SQLiteLuaLibrary : DelegatingLuaLibrary + public sealed class SQLiteLuaLibrary : LuaLibraryBase { - public SQLiteLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public SQLiteLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "SQL"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/SaveStateLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/SaveStateLuaLibrary.cs index 974960cb3a..3952ff001e 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/SaveStateLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/SaveStateLuaLibrary.cs @@ -4,10 +4,10 @@ using NLua; namespace BizHawk.Client.Common { - public sealed class SaveStateLuaLibrary : DelegatingLuaLibrary + public sealed class SaveStateLuaLibrary : LuaLibraryBase { - public SaveStateLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public SaveStateLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "savestate"; diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/UserDataLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/UserDataLuaLibrary.cs index 0ab91fb103..de68eeae22 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/UserDataLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/UserDataLuaLibrary.cs @@ -6,10 +6,10 @@ using NLua; namespace BizHawk.Client.Common { [Description("A library for setting and retrieving dynamic data that will be saved and loaded with savestates")] - public sealed class UserDataLuaLibrary : DelegatingLuaLibrary + public sealed class UserDataLuaLibrary : LuaLibraryBase { - public UserDataLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public UserDataLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "userdata"; diff --git a/src/BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs b/src/BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs deleted file mode 100644 index cdcd730cdc..0000000000 --- a/src/BizHawk.Client.Common/lua/DelegatingLuaLibrary.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -using NLua; - -namespace BizHawk.Client.Common -{ - /// Extends by including an for the library to delegate its calls through. - public abstract class DelegatingLuaLibrary : LuaLibraryBase - { - protected DelegatingLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} - - public ApiContainer APIs { protected get; set; } - } -} diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/BitLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/BitLuaLibrary.cs index b95975b3c6..07b4ea4c9d 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/BitLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/BitLuaLibrary.cs @@ -9,8 +9,8 @@ namespace BizHawk.Client.Common [Description("A library for performing standard bitwise operations.")] public sealed class BitLuaLibrary : LuaLibraryBase { - public BitLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public BitLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "bit"; diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/EventsLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/EventsLuaLibrary.cs index 91a72ca34a..b23a05065f 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/EventsLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/EventsLuaLibrary.cs @@ -24,8 +24,8 @@ namespace BizHawk.Client.Common [OptionalService] private IMemoryDomains Domains { get; set; } - public EventsLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public EventsLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "event"; diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/GenesisLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/GenesisLuaLibrary.cs index d7ed073f10..049b0016d5 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/GenesisLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/GenesisLuaLibrary.cs @@ -9,10 +9,10 @@ using BizHawk.Emulation.Cores.Consoles.Sega.gpgx; namespace BizHawk.Client.Common { [Description("Functions specific to GenesisHawk (functions may not run when an Genesis game is not loaded)")] - public sealed class GenesisLuaLibrary : DelegatingLuaLibrary + public sealed class GenesisLuaLibrary : LuaLibraryBase { - public GenesisLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public GenesisLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "genesis"; diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/MainMemoryLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/MainMemoryLuaLibrary.cs index c2c1677259..491ff25b0f 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/MainMemoryLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/MainMemoryLuaLibrary.cs @@ -9,7 +9,7 @@ using NLua; namespace BizHawk.Client.Common { [Description("Main memory library reads and writes from the Main memory domain (the default memory domain set by any given core)")] - public sealed class MainMemoryLuaLibrary : DelegatingLuaLibrary + public sealed class MainMemoryLuaLibrary : LuaLibraryBase { [RequiredService] private IEmulator Emulator { get; set; } @@ -17,8 +17,8 @@ namespace BizHawk.Client.Common [OptionalService] private IMemoryDomains MemoryDomainCore { get; set; } - public MainMemoryLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public MainMemoryLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "mainmemory"; diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/NESLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/NESLuaLibrary.cs index 0e53622216..9fe5eb2520 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/NESLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/NESLuaLibrary.cs @@ -12,7 +12,7 @@ using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; namespace BizHawk.Client.Common { [Description("Functions related specifically to Nes Cores")] - public sealed class NESLuaLibrary : DelegatingLuaLibrary + public sealed class NESLuaLibrary : LuaLibraryBase { // TODO: // perhaps with the new core config system, one could @@ -21,8 +21,8 @@ namespace BizHawk.Client.Common [OptionalService] private IMemoryDomains MemoryDomains { get; set; } - public NESLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public NESLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "nes"; diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/SNESLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/SNESLuaLibrary.cs index bcf964da58..15319f495c 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/SNESLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/SNESLuaLibrary.cs @@ -8,10 +8,10 @@ using BizHawk.Emulation.Cores.Nintendo.SNES; namespace BizHawk.Client.Common { [Description("Functions specific to SNESHawk (functions may not run when an SNES game is not loaded)")] - public sealed class SNESLuaLibrary : DelegatingLuaLibrary + public sealed class SNESLuaLibrary : LuaLibraryBase { - public SNESLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public SNESLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "snes"; diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/StringLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/StringLuaLibrary.cs index 85bc01377a..2f66af820f 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/StringLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/StringLuaLibrary.cs @@ -11,8 +11,8 @@ namespace BizHawk.Client.Common { public override string Name => "bizstring"; - public StringLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public StringLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} [LuaMethodExample("local stbizhex = bizstring.hex( -12345 );")] [LuaMethod("hex", "Converts the number to a string representation of the hexadecimal value of the given number")] diff --git a/src/BizHawk.Client.Common/lua/LuaLibraryBase.cs b/src/BizHawk.Client.Common/lua/LuaLibraryBase.cs index 6be0004fa8..eab11b17ec 100644 --- a/src/BizHawk.Client.Common/lua/LuaLibraryBase.cs +++ b/src/BizHawk.Client.Common/lua/LuaLibraryBase.cs @@ -8,11 +8,12 @@ namespace BizHawk.Client.Common { public abstract class LuaLibraryBase { - protected LuaLibraryBase(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) + protected LuaLibraryBase(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) { LogOutputCallback = logOutputCallback; Lua = lua; _luaLibsImpl = luaLibsImpl; + APIs = apiContainer; } protected static LuaFile CurrentFile { get; private set; } @@ -22,6 +23,8 @@ namespace BizHawk.Client.Common public abstract string Name { get; } + protected readonly ApiContainer APIs; + protected readonly Action LogOutputCallback; public Lua Lua { get; } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ConsoleLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ConsoleLuaLibrary.cs index fbb785013d..eee4875db4 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ConsoleLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ConsoleLuaLibrary.cs @@ -11,8 +11,8 @@ namespace BizHawk.Client.EmuHawk { public ToolManager Tools { get; set; } - public ConsoleLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public ConsoleLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "console"; diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs index 6d708eb9f9..1cdfdd81b1 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs @@ -14,8 +14,8 @@ namespace BizHawk.Client.EmuHawk [Description("A library for creating and managing custom dialogs")] public sealed class FormsLuaLibrary : LuaLibraryBase { - public FormsLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public FormsLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "forms"; diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index 7cd70fd064..981ba3398c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -18,8 +18,8 @@ namespace BizHawk.Client.EmuHawk { public ToolManager Tools { get; set; } - public TAStudioLuaLibrary(LuaLibraries luaLibsImpl, Lua lua, Action logOutputCallback) - : base(luaLibsImpl, lua, logOutputCallback) {} + public TAStudioLuaLibrary(LuaLibraries luaLibsImpl, ApiContainer apiContainer, Lua lua, Action logOutputCallback) + : base(luaLibsImpl, apiContainer, lua, logOutputCallback) {} public override string Name => "tastudio"; diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs index bf9169b8e9..bca3dfb0f4 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Win32LuaLibraries.cs @@ -64,7 +64,7 @@ namespace BizHawk.Client.EmuHawk if (addLibrary) { - var instance = (LuaLibraryBase) Activator.CreateInstance(lib, this, _lua, (Action) LogToLuaConsole); + var instance = (LuaLibraryBase) Activator.CreateInstance(lib, this, apiContainer, _lua, (Action) LogToLuaConsole); ServiceInjector.UpdateServices(serviceProvider, instance); // TODO: make EmuHawk libraries have a base class with common properties such as this @@ -92,8 +92,6 @@ namespace BizHawk.Client.EmuHawk tastudioLib.Tools = _mainForm.Tools; } - if (instance is DelegatingLuaLibrary dlgInstance) dlgInstance.APIs = apiContainer; - EnumerateLuaFunctions(instance.Name, lib, instance); Libraries.Add(lib, instance); }