Move two methods from LuaConsole to ILuaLibraries because they make more sense there. (They had no need of a reference to a LuaConsole.)

This also supports testing by removing the need to use a LuaConsole in tests.
This commit is contained in:
SuuperW 2023-09-19 03:48:05 -05:00
parent d2152010d3
commit 7b1417acae
3 changed files with 37 additions and 28 deletions

View File

@ -53,5 +53,9 @@ namespace BizHawk.Client.Common
void ExecuteString(string command);
(bool WaitForFrame, bool Terminated) ResumeScript(LuaFile lf);
void EnableLuaFile(LuaFile item);
void DisableLuaScript(LuaFile file);
}
}

View File

@ -352,5 +352,33 @@ namespace BizHawk.Client.Common
{
_currThread.Yield();
}
public void DisableLuaScript(LuaFile file)
{
if (file.IsSeparator) return;
file.State = LuaFile.RunState.Disabled;
if (file.Thread is not null)
{
CallExitEvent(file);
RegisteredFunctions.RemoveForFile(file, _mainFormApi.Emulator);
file.Stop();
}
}
public void EnableLuaFile(LuaFile item)
{
LuaSandbox.Sandbox(null, () =>
{
SpawnAndSetFileThread(item.Path, item);
LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(item.Path));
}, () =>
{
item.State = LuaFile.RunState.Disabled;
});
// there used to be a call here which did a redraw of the Gui/OSD, which included a call to `Tools.UpdateToolsAfter` --yoshi
}
}
}

View File

@ -204,7 +204,7 @@ namespace BizHawk.Client.EmuHawk
// we don't use runningScripts here as the other scripts need to be stopped too
foreach (var file in LuaImp.ScriptList)
{
DisableLuaScript(file);
LuaImp.DisableLuaScript(file);
}
}
@ -368,7 +368,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!item.IsSeparator)
{
DisableLuaScript(item);
LuaImp.DisableLuaScript(item);
RemoveFileWatcher(item);
}
LuaImp.ScriptList.Remove(item);
@ -899,16 +899,7 @@ namespace BizHawk.Client.EmuHawk
{
try
{
LuaSandbox.Sandbox(null, () =>
{
LuaImp.SpawnAndSetFileThread(item.Path, item);
LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(item.Path));
}, () =>
{
item.State = LuaFile.RunState.Disabled;
});
// there used to be a call here which did a redraw of the Gui/OSD, which included a call to `Tools.UpdateToolsAfter` --yoshi
LuaImp.EnableLuaFile(item);
}
catch (IOException)
{
@ -1064,7 +1055,7 @@ namespace BizHawk.Client.EmuHawk
{
foreach (var file in LuaImp.ScriptList)
{
DisableLuaScript(file);
LuaImp.DisableLuaScript(file);
}
UpdateDialog();
}
@ -1497,25 +1488,11 @@ namespace BizHawk.Client.EmuHawk
}
else if (!file.Enabled && file.Thread is not null)
{
DisableLuaScript(file);
LuaImp.DisableLuaScript(file);
// there used to be a call here which did a redraw of the Gui/OSD, which included a call to `Tools.UpdateToolsAfter` --yoshi
}
}
private void DisableLuaScript(LuaFile file)
{
if (file.IsSeparator) return;
file.State = LuaFile.RunState.Disabled;
if (file.Thread is not null)
{
LuaImp.CallExitEvent(file);
LuaImp.RegisteredFunctions.RemoveForFile(file, Emulator);
file.Stop();
}
}
private void RefreshLuaScript(LuaFile file)
{
ToggleLuaScript(file);