IPlatformLuaLibEnv -> ILuaLibraries / Win32LuaLibraries -> LuaLibraries, cleanup usage of it, fix doc error in client.gettool
This commit is contained in:
parent
f101cb5a54
commit
b3c7f0fa48
|
@ -26,7 +26,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public IMainFormForApi MainForm { get; set; }
|
||||
|
||||
public ClientLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public ClientLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "client";
|
||||
|
@ -332,7 +332,7 @@ namespace BizHawk.Client.Common
|
|||
=> _th.EnumerateToLuaTable(APIs.Tool.AvailableTools.Select(tool => tool.Name.ToLower()), indexFrom: 0);
|
||||
|
||||
[LuaMethodExample("local nlcliget = client.gettool( \"Tool name\" );")]
|
||||
[LuaMethod("gettool", "Returns an object that represents a tool of the given name (not case sensitive). If the tool is not open, it will be loaded if available. Use gettools to get a list of names")]
|
||||
[LuaMethod("gettool", "Returns an object that represents a tool of the given name (not case sensitive). If the tool is not open, it will be loaded if available. Use getavailabletools to get a list of names")]
|
||||
public LuaTable GetTool(string name)
|
||||
{
|
||||
var selectedTool = APIs.Tool.GetTool(name);
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
private readonly IDictionary<Guid, ClientWebSocketWrapper> _websockets = new Dictionary<Guid, ClientWebSocketWrapper>();
|
||||
|
||||
public CommLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public CommLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "comm";
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using NLua;
|
||||
|
@ -14,7 +13,7 @@ namespace BizHawk.Client.Common
|
|||
public Action FrameAdvanceCallback { get; set; }
|
||||
public Action YieldCallback { get; set; }
|
||||
|
||||
public EmulationLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public EmulationLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "emu";
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed class GameInfoLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public GameInfoLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public GameInfoLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "gameinfo";
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public Func<int, int, int?, int?, LuaTable> CreateLuaCanvasCallback { get; set; }
|
||||
|
||||
public GuiLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public GuiLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "gui";
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed class InputLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public InputLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public InputLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "input";
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using NLua;
|
||||
|
||||
|
@ -9,7 +8,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed class JoypadLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public JoypadLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public JoypadLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "joypad";
|
||||
|
|
|
@ -11,7 +11,7 @@ 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 : LuaLibraryBase
|
||||
{
|
||||
public MemoryLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public MemoryLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "memory";
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed class MemorySavestateLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public MemorySavestateLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public MemorySavestateLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "memorysavestate";
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using NLua;
|
||||
|
||||
|
@ -8,7 +7,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed class MovieLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public MovieLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public MovieLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "movie";
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace BizHawk.Client.Common
|
|||
[Description("A library for performing SQLite operations.")]
|
||||
public sealed class SQLiteLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public SQLiteLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public SQLiteLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "SQL";
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed class SaveStateLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public SaveStateLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public SaveStateLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "savestate";
|
||||
|
|
|
@ -10,7 +10,7 @@ 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 : LuaLibraryBase
|
||||
{
|
||||
public UserDataLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public UserDataLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "userdata";
|
||||
|
|
|
@ -2,10 +2,11 @@ using System;
|
|||
|
||||
using NLua;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
/// <remarks>TODO replace with impl.</remarks>
|
||||
public interface IPlatformLuaLibEnv
|
||||
public interface ILuaLibraries
|
||||
{
|
||||
LuaDocumentation Docs { get; }
|
||||
|
||||
|
@ -26,6 +27,14 @@ namespace BizHawk.Client.Common
|
|||
|
||||
void CallSaveStateEvent(string name);
|
||||
|
||||
void CallFrameBeforeEvent();
|
||||
|
||||
void CallFrameAfterEvent();
|
||||
|
||||
void CallExitEvent(LuaFile lf);
|
||||
|
||||
void Close();
|
||||
|
||||
INamedLuaFunction CreateAndRegisterNamedFunction(
|
||||
LuaFunction function,
|
||||
string theEvent,
|
||||
|
@ -35,8 +44,14 @@ namespace BizHawk.Client.Common
|
|||
|
||||
NLuaTableHelper GetTableHelper();
|
||||
|
||||
void Restart(IEmulatorServiceProvider newServiceProvider, Config config, IEmulator emulator, IGameInfo game);
|
||||
|
||||
bool RemoveNamedFunctionMatching(Func<INamedLuaFunction, bool> predicate);
|
||||
|
||||
void SpawnAndSetFileThread(string pathToLoad, LuaFile lf);
|
||||
|
||||
void ExecuteString(string command);
|
||||
|
||||
(bool WaitForFrame, bool Terminated) ResumeScript(LuaFile lf);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ namespace BizHawk.Client.Common
|
|||
[Description("A library for performing standard bitwise operations.")]
|
||||
public sealed class BitLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public BitLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public BitLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "bit";
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace BizHawk.Client.Common
|
|||
[OptionalService]
|
||||
private IMemoryDomains Domains { get; set; }
|
||||
|
||||
public EventsLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public EventsLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "event";
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BizHawk.Client.Common
|
|||
[Description("Functions specific to GenesisHawk (functions may not run when an Genesis game is not loaded)")]
|
||||
public sealed class GenesisLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public GenesisLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public GenesisLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "genesis";
|
||||
|
|
|
@ -12,7 +12,7 @@ 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 : LuaLibraryBase
|
||||
{
|
||||
public MainMemoryLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public MainMemoryLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "mainmemory";
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BizHawk.Client.Common
|
|||
[Description("Functions specific to NDSHawk (functions may not run when an NDS game is not loaded)")]
|
||||
public sealed class NDSLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public NDSLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public NDSLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "nds";
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace BizHawk.Client.Common
|
|||
[Description("Functions related specifically to Nes Cores")]
|
||||
public sealed class NESLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public NESLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public NESLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "nes";
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BizHawk.Client.Common
|
|||
[Description("Functions specific to SNESHawk (functions may not run when an SNES game is not loaded)")]
|
||||
public sealed class SNESLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public SNESLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public SNESLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "snes";
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public override string Name => "bizstring";
|
||||
|
||||
public StringLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public StringLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
[LuaMethodExample("local stbizhex = bizstring.hex( -12345 );")]
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public abstract class LuaLibraryBase
|
||||
{
|
||||
public PathEntryCollection PathEntries { get; set; }
|
||||
|
||||
protected LuaLibraryBase(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
protected LuaLibraryBase(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
{
|
||||
LogOutputCallback = logOutputCallback;
|
||||
_luaLibsImpl = luaLibsImpl;
|
||||
|
@ -24,7 +19,7 @@ namespace BizHawk.Client.Common
|
|||
protected static LuaFile CurrentFile { get; private set; }
|
||||
|
||||
private static Thread _currentHostThread;
|
||||
private static readonly object ThreadMutex = new object();
|
||||
private static readonly object ThreadMutex = new();
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
|
@ -32,7 +27,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
protected readonly Action<string> LogOutputCallback;
|
||||
|
||||
protected readonly IPlatformLuaLibEnv _luaLibsImpl;
|
||||
protected readonly ILuaLibraries _luaLibsImpl;
|
||||
|
||||
protected readonly NLuaTableHelper _th;
|
||||
|
||||
|
|
|
@ -382,6 +382,7 @@
|
|||
<Compile Update="tools/Lua/LuaFunctionsForm.cs" SubType="Form" />
|
||||
<Compile Update="tools/Lua/LuaFunctionsForm.Designer.cs" DependentUpon="LuaFunctionsForm.cs" />
|
||||
<EmbeddedResource Update="tools/Lua/LuaFunctionsForm.resx" DependentUpon="LuaFunctionsForm.cs" />
|
||||
<Compile Update="tools/Lua/LuaLibraries.cs" />
|
||||
<Compile Update="tools/Lua/LuaPictureBox.cs" SubType="Component" />
|
||||
<Compile Update="tools/Lua/LuaRegisteredFunctionsList.cs" SubType="Form" />
|
||||
<Compile Update="tools/Lua/LuaRegisteredFunctionsList.Designer.cs" DependentUpon="LuaRegisteredFunctionsList.cs" />
|
||||
|
@ -390,8 +391,6 @@
|
|||
<Compile Update="tools/Lua/LuaWinform.cs" SubType="Form" />
|
||||
<Compile Update="tools/Lua/LuaWinform.Designer.cs" DependentUpon="LuaWinform.cs" />
|
||||
<EmbeddedResource Update="tools/Lua/LuaWinform.resx" DependentUpon="LuaWinform.cs" />
|
||||
<Compile Update="tools/Lua/UnixLuaLibraries.cs" DependentUpon="LuaLibraries.cs" />
|
||||
<Compile Update="tools/Lua/Win32LuaLibraries.cs" DependentUpon="LuaLibraries.cs" />
|
||||
<Compile Update="tools/Macros/MacroInput.ButtonSelect.cs" SubType="Form" />
|
||||
<Compile Update="tools/Macros/MacroInput.cs" SubType="Form" />
|
||||
<Compile Update="tools/Macros/MacroInput.Designer.cs" DependentUpon="MacroInput.cs" />
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public ToolManager Tools { get; set; }
|
||||
|
||||
public ConsoleLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public ConsoleLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "console";
|
||||
|
|
|
@ -7,7 +7,6 @@ using System.Linq;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
|
||||
using NLua;
|
||||
|
||||
|
@ -18,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
private const string ERR_MSG_CONTROL_NOT_LPB = "Drawing functions can only be used on PictureBox components.";
|
||||
|
||||
public FormsLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public FormsLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public Form MainForm { get; set; }
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public ToolManager Tools { get; set; }
|
||||
|
||||
public TAStudioLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
public TAStudioLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
|
||||
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
|
||||
|
||||
public override string Name => "tastudio";
|
||||
|
|
|
@ -128,7 +128,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
DisplayManager.ClearApiHawkSurfaces();
|
||||
ResetDrawSurfacePadding();
|
||||
ClearFileWatches();
|
||||
(LuaImp as Win32LuaLibraries)?.Close();
|
||||
LuaImp?.Close();
|
||||
DisplayManager.OSD.ClearGuiText();
|
||||
}
|
||||
else
|
||||
|
@ -146,7 +146,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
_defaultSplitDistance = splitContainer1.SplitterDistance;
|
||||
}
|
||||
|
||||
public IPlatformLuaLibEnv LuaImp { get; private set; }
|
||||
public ILuaLibraries LuaImp { get; private set; }
|
||||
|
||||
private IEnumerable<LuaFile> SelectedItems => LuaListView.SelectedRows.Select(index => LuaImp.ScriptList[index]);
|
||||
|
||||
|
@ -185,21 +185,22 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public override void Restart()
|
||||
{
|
||||
var runningScripts = new List<LuaFile>();
|
||||
List<LuaFile> runningScripts = new();
|
||||
|
||||
if (LuaImp is Win32LuaLibraries luaLibsImpl) // Things we need to do with the existing LuaImp before we can make a new one
|
||||
// Things we need to do with the existing LuaImp before we can make a new one
|
||||
if (LuaImp is not null)
|
||||
{
|
||||
if (luaLibsImpl.IsRebootingCore)
|
||||
if (LuaImp.IsRebootingCore)
|
||||
{
|
||||
// Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
|
||||
luaLibsImpl.Restart(Emulator.ServiceProvider, Config, Emulator, Game);
|
||||
LuaImp.Restart(Emulator.ServiceProvider, Config, Emulator, Game);
|
||||
return;
|
||||
}
|
||||
|
||||
runningScripts = luaLibsImpl.ScriptList.Where(lf => lf.Enabled).ToList();
|
||||
runningScripts = LuaImp.ScriptList.Where(lf => lf.Enabled).ToList();
|
||||
|
||||
// we don't use runningScripts here as the other scripts need to be stopped too
|
||||
foreach (var file in luaLibsImpl.ScriptList)
|
||||
foreach (var file in LuaImp.ScriptList)
|
||||
{
|
||||
DisableLuaScript(file);
|
||||
}
|
||||
|
@ -207,8 +208,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
LuaFileList newScripts = new(LuaImp?.ScriptList, onChanged: SessionChangedCallback);
|
||||
LuaFunctionList registeredFuncList = new(onChanged: UpdateRegisteredFunctionsDialog);
|
||||
(LuaImp as Win32LuaLibraries)?.Close();
|
||||
LuaImp = new Win32LuaLibraries(
|
||||
LuaImp?.Close();
|
||||
LuaImp = new LuaLibraries(
|
||||
newScripts,
|
||||
registeredFuncList,
|
||||
Emulator.ServiceProvider,
|
||||
|
@ -306,7 +307,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void OnLuaFileChanged(LuaFile item)
|
||||
{
|
||||
if (item.Enabled && LuaImp?.ScriptList.Contains(item) == true)
|
||||
if (item.Enabled && LuaImp.ScriptList.Contains(item) == true)
|
||||
{
|
||||
RefreshLuaScript(item);
|
||||
}
|
||||
|
@ -314,11 +315,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void LoadLuaFile(string path)
|
||||
{
|
||||
if (!(LuaImp is Win32LuaLibraries luaLibsImpl)) return;
|
||||
|
||||
var absolutePath = Path.GetFullPath(path);
|
||||
|
||||
var alreadyLoadedFile = luaLibsImpl.ScriptList.FirstOrDefault(t => absolutePath == t.Path);
|
||||
var alreadyLoadedFile = LuaImp.ScriptList.FirstOrDefault(t => absolutePath == t.Path);
|
||||
if (alreadyLoadedFile is not null)
|
||||
{
|
||||
if (!alreadyLoadedFile.Enabled && !Settings.DisableLuaScriptsOnLoad)
|
||||
|
@ -330,8 +329,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
var luaFile = new LuaFile("", absolutePath);
|
||||
|
||||
luaLibsImpl.ScriptList.Add(luaFile);
|
||||
LuaListView.RowCount = luaLibsImpl.ScriptList.Count;
|
||||
LuaImp.ScriptList.Add(luaFile);
|
||||
LuaListView.RowCount = LuaImp.ScriptList.Count;
|
||||
Config.RecentLua.Add(absolutePath);
|
||||
|
||||
if (!Settings.DisableLuaScriptsOnLoad)
|
||||
|
@ -355,11 +354,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void RemoveLuaFile(string path)
|
||||
{
|
||||
if (LuaImp is not Win32LuaLibraries luaLibsImpl) return;
|
||||
|
||||
var absolutePath = Path.GetFullPath(path);
|
||||
|
||||
var luaFile = luaLibsImpl.ScriptList.FirstOrDefault(t => absolutePath == t.Path);
|
||||
var luaFile = LuaImp.ScriptList.FirstOrDefault(t => absolutePath == t.Path);
|
||||
if (luaFile is not null)
|
||||
{
|
||||
RemoveLuaFile(luaFile);
|
||||
|
@ -548,22 +545,22 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
protected override void UpdateBefore()
|
||||
{
|
||||
if (LuaImp is not Win32LuaLibraries luaLibsImpl || luaLibsImpl.IsUpdateSupressed)
|
||||
if (LuaImp.IsUpdateSupressed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
luaLibsImpl.CallFrameBeforeEvent();
|
||||
LuaImp.CallFrameBeforeEvent();
|
||||
}
|
||||
|
||||
protected override void UpdateAfter()
|
||||
{
|
||||
if (LuaImp is not Win32LuaLibraries luaLibsImpl || luaLibsImpl.IsUpdateSupressed)
|
||||
if (LuaImp.IsUpdateSupressed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
luaLibsImpl.CallFrameAfterEvent();
|
||||
LuaImp.CallFrameAfterEvent();
|
||||
ResumeScripts(true);
|
||||
}
|
||||
|
||||
|
@ -605,15 +602,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// <param name="includeFrameWaiters">should frame waiters be waken up? only use this immediately before a frame of emulation</param>
|
||||
public void ResumeScripts(bool includeFrameWaiters)
|
||||
{
|
||||
if (LuaImp is not Win32LuaLibraries luaLibsImpl
|
||||
|| !luaLibsImpl.ScriptList.Any()
|
||||
|| luaLibsImpl.IsUpdateSupressed
|
||||
if (!LuaImp.ScriptList.Any()
|
||||
|| LuaImp.IsUpdateSupressed
|
||||
|| (MainForm.IsTurboing && !Config.RunLuaDuringTurbo))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var lf in luaLibsImpl.ScriptList.Where(static lf => lf.State is LuaFile.RunState.Running && lf.Thread is not null))
|
||||
foreach (var lf in LuaImp.ScriptList.Where(static lf => lf.State is LuaFile.RunState.Running && lf.Thread is not null))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -622,10 +618,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
var prohibit = lf.FrameWaiting && !includeFrameWaiters;
|
||||
if (!prohibit)
|
||||
{
|
||||
var (waitForFrame, terminated) = luaLibsImpl.ResumeScript(lf);
|
||||
var (waitForFrame, terminated) = LuaImp.ResumeScript(lf);
|
||||
if (terminated)
|
||||
{
|
||||
luaLibsImpl.CallExitEvent(lf);
|
||||
LuaImp.CallExitEvent(lf);
|
||||
lf.Stop();
|
||||
DetachRegisteredFunctions(lf);
|
||||
UpdateDialog();
|
||||
|
@ -876,9 +872,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void ToggleScriptMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!(LuaImp is Win32LuaLibraries luaLibsImpl)) return;
|
||||
var files = !SelectedFiles.Any() && Settings.ToggleAllIfNoneSelected
|
||||
? luaLibsImpl.ScriptList
|
||||
? LuaImp.ScriptList
|
||||
: SelectedFiles;
|
||||
foreach (var file in files)
|
||||
{
|
||||
|
@ -890,12 +885,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void EnableLuaFile(LuaFile item)
|
||||
{
|
||||
if (!(LuaImp is Win32LuaLibraries luaLibsImpl)) return;
|
||||
try
|
||||
{
|
||||
LuaSandbox.Sandbox(null, () =>
|
||||
{
|
||||
luaLibsImpl.SpawnAndSetFileThread(item.Path, item);
|
||||
LuaImp.SpawnAndSetFileThread(item.Path, item);
|
||||
LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(item.Path));
|
||||
}, () =>
|
||||
{
|
||||
|
@ -1355,9 +1349,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void RefreshScriptMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!(LuaImp is Win32LuaLibraries luaLibsImpl)) return;
|
||||
var files = !SelectedFiles.Any() && Settings.ToggleAllIfNoneSelected
|
||||
? luaLibsImpl.ScriptList
|
||||
? LuaImp.ScriptList
|
||||
: SelectedFiles;
|
||||
foreach (var file in files) RefreshLuaScript(file);
|
||||
UpdateDialog();
|
||||
|
@ -1372,12 +1365,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
// TODO: Maybe make these try-catches more general
|
||||
if (!string.IsNullOrWhiteSpace(InputBox.Text))
|
||||
{
|
||||
if (!(LuaImp is Win32LuaLibraries luaLibsImpl))
|
||||
{
|
||||
WriteLine("can't use the REPL either dude");
|
||||
return;
|
||||
}
|
||||
|
||||
if (InputBox.Text.Contains("emu.frameadvance("))
|
||||
{
|
||||
WriteLine("emu.frameadvance() can not be called from the console");
|
||||
|
@ -1386,12 +1373,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
LuaSandbox.Sandbox(null, () =>
|
||||
{
|
||||
luaLibsImpl.ExecuteString($"console.log({InputBox.Text})");
|
||||
LuaImp.ExecuteString($"console.log({InputBox.Text})");
|
||||
}, () =>
|
||||
{
|
||||
LuaSandbox.Sandbox(null, () =>
|
||||
{
|
||||
luaLibsImpl.ExecuteString(InputBox.Text);
|
||||
LuaImp.ExecuteString(InputBox.Text);
|
||||
|
||||
if (OutputBox.Text == consoleBeforeCall)
|
||||
{
|
||||
|
@ -1473,11 +1460,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void LuaListView_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
if (!(LuaImp is Win32LuaLibraries luaLibsImpl)) return;
|
||||
var index = LuaListView.CurrentCell?.RowIndex;
|
||||
if (index < luaLibsImpl.ScriptList.Count)
|
||||
if (index < LuaImp.ScriptList.Count)
|
||||
{
|
||||
var file = luaLibsImpl.ScriptList[index.Value];
|
||||
var file = LuaImp.ScriptList[index.Value];
|
||||
ToggleLuaScript(file);
|
||||
UpdateDialog();
|
||||
}
|
||||
|
@ -1485,8 +1471,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void ToggleLuaScript(LuaFile file)
|
||||
{
|
||||
if (!(LuaImp is Win32LuaLibraries luaLibsImpl)) return;
|
||||
|
||||
if (file.IsSeparator)
|
||||
{
|
||||
return;
|
||||
|
@ -1496,7 +1480,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (file.Enabled && file.Thread is null)
|
||||
{
|
||||
luaLibsImpl.RegisteredFunctions.RemoveForFile(file, Emulator); // First remove any existing registered functions for this file
|
||||
LuaImp.RegisteredFunctions.RemoveForFile(file, Emulator); // First remove any existing registered functions for this file
|
||||
EnableLuaFile(file);
|
||||
}
|
||||
else if (!file.Enabled && file.Thread is not null)
|
||||
|
@ -1508,16 +1492,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void DisableLuaScript(LuaFile file)
|
||||
{
|
||||
if (LuaImp is not Win32LuaLibraries luaLibsImpl) return;
|
||||
|
||||
if (file.IsSeparator) return;
|
||||
|
||||
file.State = LuaFile.RunState.Disabled;
|
||||
|
||||
if (file.Thread is not null)
|
||||
{
|
||||
luaLibsImpl.CallExitEvent(file);
|
||||
luaLibsImpl.RegisteredFunctions.RemoveForFile(file, Emulator);
|
||||
LuaImp.CallExitEvent(file);
|
||||
LuaImp.RegisteredFunctions.RemoveForFile(file, Emulator);
|
||||
file.Stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ using BizHawk.Client.Common;
|
|||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public class Win32LuaLibraries : IPlatformLuaLibEnv
|
||||
public class LuaLibraries : ILuaLibraries
|
||||
{
|
||||
public Win32LuaLibraries(
|
||||
public LuaLibraries(
|
||||
LuaFileList scriptList,
|
||||
LuaFunctionList registeredFuncList,
|
||||
IEmulatorServiceProvider serviceProvider,
|
||||
|
@ -46,7 +46,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
_lua.State.Encoding = Encoding.UTF8;
|
||||
_th = new NLuaTableHelper(_lua, LogToLuaConsole);
|
||||
_displayManager = displayManager;
|
||||
_inputManager = inputManager;
|
||||
|
@ -103,7 +102,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
_lua.RegisterFunction("print", this, typeof(Win32LuaLibraries).GetMethod(nameof(Print)));
|
||||
_lua.RegisterFunction("print", this, typeof(LuaLibraries).GetMethod(nameof(Print)));
|
||||
if (OSTailoredCode.IsUnixHost)
|
||||
{
|
||||
// add %exe%/Lua to library resolution pathset (LUA_PATH)
|
||||
|
@ -113,7 +112,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
packageTable["path"] = $"{luaPath}/?.lua;{luaPath}?/init.lua;{packageTable["path"]}";
|
||||
}
|
||||
|
||||
EmulationLuaLibrary.FrameAdvanceCallback = Frameadvance;
|
||||
EmulationLuaLibrary.FrameAdvanceCallback = FrameAdvance;
|
||||
EmulationLuaLibrary.YieldCallback = EmuYield;
|
||||
|
||||
EnumerateLuaFunctions(nameof(LuaCanvas), typeof(LuaCanvas), null); // add LuaCanvas to Lua function reference table
|
||||
|
@ -129,7 +128,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private readonly MainForm _mainForm;
|
||||
|
||||
private Lua _lua = new();
|
||||
private Lua _lua = new() { State = { Encoding = Encoding.UTF8 } };
|
||||
private LuaThread _currThread;
|
||||
|
||||
private readonly NLuaTableHelper _th;
|
||||
|
@ -142,6 +141,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private EmulationLuaLibrary EmulationLuaLibrary => (EmulationLuaLibrary)Libraries[typeof(EmulationLuaLibrary)];
|
||||
|
||||
// nb: KeraLua isn't really the engine, NLua does the heavy lifting (KeraLua is just a thin layer for native lua)
|
||||
// this is just done to differentiate against the old NLua engine, which was backed by KopiLua (c# impl of lua) instead of KeraLua
|
||||
public string EngineName => "KeraLua";
|
||||
|
||||
public bool IsRebootingCore { get; set; }
|
||||
|
@ -277,7 +278,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
ScriptList.Clear();
|
||||
FormsLibrary.DestroyAll();
|
||||
_lua.Dispose();
|
||||
_lua = new Lua();
|
||||
_lua = null;
|
||||
}
|
||||
|
||||
public INamedLuaFunction CreateAndRegisterNamedFunction(
|
||||
|
@ -306,7 +307,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
var content = File.ReadAllText(file);
|
||||
var main = _lua.LoadString(content, "main");
|
||||
_lua.NewThread(main, out var ret);
|
||||
ret.State.Encoding = Encoding.UTF8;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
_logToLuaConsoleCallback(outputs);
|
||||
}
|
||||
|
||||
private void Frameadvance()
|
||||
private void FrameAdvance()
|
||||
{
|
||||
FrameAdvanceRequested = true;
|
||||
_currThread.Yield();
|
Loading…
Reference in New Issue