Fix `--lua=*.luases` being interpreted as a script (fixes #3814)

This commit is contained in:
James Groom 2023-10-29 06:38:06 +10:00 committed by GitHub
parent db589ee856
commit aaf46cc9a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 11 deletions

View File

@ -710,7 +710,7 @@ namespace BizHawk.Client.EmuHawk
//load Lua Script if requested in the command line arguments
if (_argParser.luaScript != null)
{
Tools.LuaConsole.LoadLuaFile(_argParser.luaScript.MakeAbsolute());
_ = Tools.LuaConsole.LoadByFileExtension(_argParser.luaScript.MakeAbsolute(), out _);
}
SetStatusBar();

View File

@ -1261,6 +1261,25 @@ namespace BizHawk.Client.EmuHawk
LuaImp.RegisteredFunctions.Clear(Emulator);
}
public bool LoadByFileExtension(string path, out bool abort)
{
var ext = Path.GetExtension(path)?.ToLowerInvariant();
if (ext is ".luases")
{
LoadLuaSession(path);
abort = true;
return true;
}
abort = false;
if (ext is ".lua" or ".txt")
{
LoadLuaFile(path);
UpdateDialog();
return true;
}
return false;
}
private void LuaConsole_DragDrop(object sender, DragEventArgs e)
{
var filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
@ -1268,16 +1287,8 @@ namespace BizHawk.Client.EmuHawk
{
foreach (var path in filePaths)
{
if (Path.GetExtension(path)?.ToLowerInvariant() == ".lua" || Path.GetExtension(path)?.ToLowerInvariant() == ".txt")
{
LoadLuaFile(path);
UpdateDialog();
}
else if (Path.GetExtension(path)?.ToLowerInvariant() == ".luases")
{
LoadLuaSession(path);
return;
}
_ = LoadByFileExtension(path, out var abort);
if (abort) return;
}
}
catch (Exception ex)