Some luaconsole refactoring and moving more logic into LuaImp
This commit is contained in:
parent
2d5c4ce893
commit
f81f745fcc
|
@ -217,10 +217,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
[LuaMethodAttributes("reboot_core", "Reboots the currently loaded core")]
|
[LuaMethodAttributes("reboot_core", "Reboots the currently loaded core")]
|
||||||
public static void RebootCore()
|
public static void RebootCore()
|
||||||
{
|
{
|
||||||
// pretty hacky.. we dont want a lua script to be able to restart itself by rebooting the core
|
((LuaConsole)GlobalWin.Tools.Get<LuaConsole>()).LuaImp.IsRebootingCore = true;
|
||||||
((LuaConsole)GlobalWin.Tools.Get<LuaConsole>()).IsRebootingCore = true;
|
|
||||||
GlobalWin.MainForm.RebootCore();
|
GlobalWin.MainForm.RebootCore();
|
||||||
((LuaConsole)GlobalWin.Tools.Get<LuaConsole>()).IsRebootingCore = false;
|
((LuaConsole)GlobalWin.Tools.Get<LuaConsole>()).LuaImp.IsRebootingCore = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaMethodAttributes("screenheight", "Gets the current height in pixels of the emulator's drawing area")]
|
[LuaMethodAttributes("screenheight", "Gets the current height in pixels of the emulator's drawing area")]
|
||||||
|
|
|
@ -81,8 +81,16 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsRebootingCore { get; set; } // pretty hacky.. we dont want a lua script to be able to restart itself by rebooting the core
|
||||||
|
|
||||||
private readonly Dictionary<Type, LuaLibraryBase> Libraries = new Dictionary<Type, LuaLibraryBase>();
|
private readonly Dictionary<Type, LuaLibraryBase> Libraries = new Dictionary<Type, LuaLibraryBase>();
|
||||||
public LuaFileList ScriptList { get; } = new LuaFileList();
|
public LuaFileList ScriptList { get; } = new LuaFileList();
|
||||||
|
|
||||||
|
public IEnumerable<LuaFile> RunningScripts
|
||||||
|
{
|
||||||
|
get { return ScriptList.Where(lf => lf.Enabled); }
|
||||||
|
}
|
||||||
|
|
||||||
private Lua _lua = new Lua();
|
private Lua _lua = new Lua();
|
||||||
private Lua _currThread;
|
private Lua _currThread;
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private readonly List<string> _consoleCommandHistory = new List<string>();
|
private readonly List<string> _consoleCommandHistory = new List<string>();
|
||||||
private int _consoleCommandHistoryIndex = -1;
|
private int _consoleCommandHistoryIndex = -1;
|
||||||
|
|
||||||
public bool IsRebootingCore { get; set; }
|
|
||||||
|
|
||||||
public ToolDialogSettings.ColumnList Columns { get; set; }
|
public ToolDialogSettings.ColumnList Columns { get; set; }
|
||||||
|
|
||||||
public class LuaConsoleSettings
|
public class LuaConsoleSettings
|
||||||
|
@ -136,25 +134,31 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void Restart()
|
public void Restart()
|
||||||
{
|
{
|
||||||
// Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
|
List<LuaFile> runningScripts = new List<LuaFile>();
|
||||||
if (IsRebootingCore)
|
|
||||||
|
if (LuaImp != null) // Things we need to do with the existing LuaImp before we can make a new one
|
||||||
{
|
{
|
||||||
|
if (LuaImp.IsRebootingCore == true)
|
||||||
|
{
|
||||||
|
// Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
|
||||||
LuaImp.Restart(Emulator.ServiceProvider);
|
LuaImp.Restart(Emulator.ServiceProvider);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LuaImp?.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface)
|
if (LuaImp.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface)
|
||||||
{
|
{
|
||||||
LuaImp.GuiLibrary.DrawFinish();
|
LuaImp.GuiLibrary.DrawFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
var runningScripts = LuaImp?.ScriptList.Where(f => f.Enabled).ToList() ?? new List<LuaFile>();
|
runningScripts = LuaImp.RunningScripts.ToList();
|
||||||
|
|
||||||
foreach (var file in runningScripts)
|
foreach (var file in runningScripts)
|
||||||
{
|
{
|
||||||
LuaImp.CallExitEvent(file.Thread);
|
LuaImp.CallExitEvent(file.Thread);
|
||||||
|
|
||||||
var functions = LuaImp.RegisteredFunctions.Where(lf => lf.Lua == file.Thread).ToList();
|
var functions = LuaImp.RegisteredFunctions
|
||||||
|
.Where(lf => lf.Lua == file.Thread)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
foreach (var function in functions)
|
foreach (var function in functions)
|
||||||
{
|
{
|
||||||
|
@ -165,6 +169,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
file.Stop();
|
file.Stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
|
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
|
||||||
LuaImp = new EmuLuaLibrary(Emulator.ServiceProvider);
|
LuaImp = new EmuLuaLibrary(Emulator.ServiceProvider);
|
||||||
|
|
Loading…
Reference in New Issue