Remove FormsLuaLibrary reference in LuaLibrariesBase and move LuaLibrariesBase to BizHawk.Client.Common (to support testing).

This commit is contained in:
SuuperW 2023-09-19 03:35:36 -05:00
parent 1623a0f44d
commit d2152010d3
2 changed files with 11 additions and 6 deletions

View File

@ -11,9 +11,8 @@ using NLua;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
namespace BizHawk.Client.Common
{
public class LuaLibrariesBase : ILuaLibraries
{
@ -127,8 +126,6 @@ namespace BizHawk.Client.EmuHawk
protected Action<object[]> _logToLuaConsoleCallback = a => Console.WriteLine("a Lua lib is logging during init and the console lib hasn't been initialised yet");
private FormsLuaLibrary FormsLibrary => (FormsLuaLibrary)Libraries[typeof(FormsLuaLibrary)];
public LuaDocumentation Docs { get; } = new LuaDocumentation();
protected EmulationLuaLibrary EmulationLuaLibrary => (EmulationLuaLibrary)Libraries[typeof(EmulationLuaLibrary)];
@ -266,7 +263,13 @@ namespace BizHawk.Client.EmuHawk
RegisteredFunctions.Clear(_mainFormApi.Emulator);
ScriptList.Clear();
FormsLibrary.DestroyAll();
foreach (var lib in Libraries.Values)
{
if (lib is IDisposable disposable)
disposable.Dispose();
}
_lua.Dispose();
_lua = null;
}

View File

@ -13,13 +13,15 @@ using NLua;
namespace BizHawk.Client.EmuHawk
{
[Description("A library for creating and managing custom dialogs")]
public sealed class FormsLuaLibrary : LuaLibraryBase
public sealed class FormsLuaLibrary : LuaLibraryBase, IDisposable
{
private const string ERR_MSG_CONTROL_NOT_LPB = "Drawing functions can only be used on PictureBox components.";
public FormsLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
public void Dispose() => DestroyAll();
public Form MainForm { get; set; }
public override string Name => "forms";