Add a return value to the main function for various purposes.

Add Lua function ExitCode to allow script writers to terminate the client with an exit code.
This commit is contained in:
pgrimsrud 2015-12-15 01:22:44 -07:00
parent a1eda8f3ab
commit bb327261ae
7 changed files with 51 additions and 10 deletions

View File

@ -24,5 +24,7 @@ namespace BizHawk.Client.EmuHawk
public static OSDManager OSD = new OSDManager();
public static DisplayManager DisplayManager;
public static GLManager GLManager;
public static int ExitCode;
}
}

View File

@ -662,6 +662,12 @@ namespace BizHawk.Client.EmuHawk
_exit = true;
}
public void CloseEmulator(int exitCode)
{
_exit = true;
_exitCode = exitCode;
}
#endregion
#region Emulation Menu

View File

@ -462,7 +462,7 @@ namespace BizHawk.Client.EmuHawk
private bool _supressSyncSettingsWarning = false;
public void ProgramRunLoop()
public int ProgramRunLoop()
{
CheckMessages(); //can someone leave a note about why this is needed?
LogConsole.PositionConsole();
@ -545,6 +545,7 @@ namespace BizHawk.Client.EmuHawk
}
Shutdown();
return _exitCode;
}
/// <summary>
@ -1322,6 +1323,7 @@ namespace BizHawk.Client.EmuHawk
private bool _avwriterpad;
private bool _exit;
private int _exitCode;
private bool _exitRequestPending;
private bool _runloopFrameProgress;
private long _frameAdvanceTimestamp;

View File

@ -34,15 +34,17 @@ namespace BizHawk.Client.EmuHawk
}
[STAThread]
static void Main(string[] args)
static int Main(string[] args)
{
SubMain(args);
return SubMain(args);
}
//NoInlining should keep this code from getting jammed into Main() which would create dependencies on types which havent been setup by the resolver yet... or something like that
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
static void SubMain(string[] args)
static int SubMain(string[] args)
{
GlobalWin.ExitCode = 0;
// this check has to be done VERY early. i stepped through a debug build with wrong .dll versions purposely used,
// and there was a TypeLoadException before the first line of SubMain was reached (some static ColorType init?)
// zero 25-dec-2012 - only do for public builds. its annoying during development
@ -55,7 +57,7 @@ namespace BizHawk.Client.EmuHawk
if (thisversion != utilversion || thisversion != emulversion)
{
MessageBox.Show("Conflicting revisions found! Don't mix .dll versions!");
return;
return -1;
}
}
@ -138,7 +140,7 @@ namespace BizHawk.Client.EmuHawk
mf.Show();
mf.Text = title;
mf.ProgramRunLoop();
GlobalWin.ExitCode = mf.ProgramRunLoop();
}
}
}
@ -169,13 +171,13 @@ namespace BizHawk.Client.EmuHawk
if (System.Diagnostics.Debugger.IsAttached)
{
mf.ProgramRunLoop();
GlobalWin.ExitCode = mf.ProgramRunLoop();
}
else
{
try
{
mf.ProgramRunLoop();
GlobalWin.ExitCode = mf.ProgramRunLoop();
}
catch (Exception e)
{
@ -227,6 +229,8 @@ namespace BizHawk.Client.EmuHawk
// GlobalWin.GL.Dispose();
//((IDisposable)GlobalWin.IGL_GL).Dispose();
//return 0 assuming things have gone well, non-zero values could be used as error codes or for scripting purposes
return GlobalWin.ExitCode;
} //SubMain
//declared here instead of a more usual place to avoid dependencies on the more usual place
@ -319,7 +323,7 @@ namespace BizHawk.Client.EmuHawk
var title = MainForm.Text;
MainForm.Show();
MainForm.Text = title;
(MainForm as MainForm).ProgramRunLoop();
GlobalWin.ExitCode = (MainForm as MainForm).ProgramRunLoop();
}
}

View File

@ -45,6 +45,15 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.MainForm.CloseEmulator();
}
[LuaMethodAttributes(
"exitCode",
"Closes the emulator and returns the provided code"
)]
public void CloseEmulatorWithCode(int exitCode)
{
GlobalWin.MainForm.CloseEmulator(exitCode);
}
[LuaMethodAttributes(
"borderheight",
"Gets the current height in pixels of the letter/pillarbox area (top side only) around the emu display surface, excluding the gameExtraPadding you've set. This function (the whole lot of them) should be renamed or refactored since the padding areas have got more complex."

View File

@ -73,7 +73,7 @@ function endScript()
client.pause()
if exitOnResults then
client.closerom()
client.exit()
client.exitCode(emu.framecount())
end
end

18
output/Lua/tasjudy.py Normal file
View File

@ -0,0 +1,18 @@
import os
import datetime
from multiprocessing import Pool
bizhawkPath = ""
romPath = ""
moviePath = ""
def emu(arg):
ret = os.system(bizhawkPath + " " + romPath + " --movie=" + moviePath)
print("Ending %d with %d at %s" % (arg,ret,datetime.datetime.now().time()))
if __name__ == '__main__':
print("Starting at %s" % datetime.datetime.now().time())
p = Pool(processes=4)
p.map(emu,range(1))
print("Ending parent at %s" % datetime.datetime.now().time())