2017-04-10 15:29:51 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
2011-05-06 23:08:50 +00:00
|
|
|
|
{
|
2013-10-28 13:48:17 +00:00
|
|
|
|
public class LuaFile
|
2012-01-10 03:12:01 +00:00
|
|
|
|
{
|
2012-03-23 19:44:47 +00:00
|
|
|
|
public LuaFile(string path)
|
2012-01-10 03:12:01 +00:00
|
|
|
|
{
|
2017-05-10 11:45:23 +00:00
|
|
|
|
Name = "";
|
2012-01-10 03:12:01 +00:00
|
|
|
|
Path = path;
|
2015-10-22 21:28:44 +00:00
|
|
|
|
State = RunState.Running;
|
2012-03-23 23:03:39 +00:00
|
|
|
|
FrameWaiting = false;
|
2012-01-10 03:12:01 +00:00
|
|
|
|
}
|
2011-05-06 23:08:50 +00:00
|
|
|
|
|
2012-03-23 19:44:47 +00:00
|
|
|
|
public LuaFile(string name, string path)
|
2012-01-10 03:12:01 +00:00
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Path = path;
|
|
|
|
|
IsSeparator = false;
|
2012-11-29 18:42:13 +00:00
|
|
|
|
|
2013-12-30 01:58:44 +00:00
|
|
|
|
// the current directory for the lua task will start off wherever the lua file is located
|
2014-06-03 02:39:15 +00:00
|
|
|
|
CurrentDirectory = System.IO.Path.GetDirectoryName(path);
|
2012-01-10 03:12:01 +00:00
|
|
|
|
}
|
2011-05-07 00:07:27 +00:00
|
|
|
|
|
2017-05-18 16:36:38 +00:00
|
|
|
|
private LuaFile(bool isSeparator)
|
2012-01-10 03:12:01 +00:00
|
|
|
|
{
|
|
|
|
|
IsSeparator = isSeparator;
|
2017-05-10 11:45:23 +00:00
|
|
|
|
Name = "";
|
|
|
|
|
Path = "";
|
2015-10-22 21:28:44 +00:00
|
|
|
|
State = RunState.Disabled;
|
2012-01-10 03:12:01 +00:00
|
|
|
|
}
|
2011-05-06 23:08:50 +00:00
|
|
|
|
|
2017-05-18 16:36:38 +00:00
|
|
|
|
public static LuaFile SeparatorInstance => new LuaFile(true);
|
|
|
|
|
|
2014-02-03 20:48:01 +00:00
|
|
|
|
public string Name { get; set; }
|
2017-05-18 16:36:38 +00:00
|
|
|
|
public string Path { get; }
|
2017-04-14 19:59:01 +00:00
|
|
|
|
public bool Enabled => State != RunState.Disabled;
|
|
|
|
|
public bool Paused => State == RunState.Paused;
|
2017-05-18 16:36:38 +00:00
|
|
|
|
public bool IsSeparator { get; }
|
2017-07-10 04:51:02 +00:00
|
|
|
|
public NLua.Lua Thread { get; set; }
|
2014-02-03 20:48:01 +00:00
|
|
|
|
public bool FrameWaiting { get; set; }
|
|
|
|
|
public string CurrentDirectory { get; set; }
|
|
|
|
|
|
2015-10-22 21:28:44 +00:00
|
|
|
|
public enum RunState
|
|
|
|
|
{
|
|
|
|
|
Disabled, Running, Paused
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RunState State { get; set; }
|
|
|
|
|
|
2017-04-15 20:37:30 +00:00
|
|
|
|
public void Stop()
|
2013-10-28 13:48:17 +00:00
|
|
|
|
{
|
2015-10-22 21:28:44 +00:00
|
|
|
|
State = RunState.Disabled;
|
2017-07-23 04:41:12 +00:00
|
|
|
|
//if(NLua.Lua.WhichLua == "NLua")
|
2017-07-15 21:36:18 +00:00
|
|
|
|
Thread.GetTable("keepalives")[Thread] = null;
|
2013-10-28 13:48:17 +00:00
|
|
|
|
Thread = null;
|
2012-01-10 03:12:01 +00:00
|
|
|
|
}
|
2011-05-06 23:08:50 +00:00
|
|
|
|
|
2012-01-10 03:12:01 +00:00
|
|
|
|
public void Toggle()
|
|
|
|
|
{
|
2015-10-22 21:28:44 +00:00
|
|
|
|
if (State == RunState.Paused)
|
2017-02-03 22:31:38 +00:00
|
|
|
|
{
|
2015-10-22 21:28:44 +00:00
|
|
|
|
State = RunState.Running;
|
2017-02-03 22:31:38 +00:00
|
|
|
|
}
|
2015-10-22 21:28:44 +00:00
|
|
|
|
else if (State == RunState.Disabled)
|
2017-02-03 22:31:38 +00:00
|
|
|
|
{
|
2015-10-22 21:28:44 +00:00
|
|
|
|
State = RunState.Running;
|
2017-02-03 22:31:38 +00:00
|
|
|
|
FrameWaiting = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
State = RunState.Disabled;
|
|
|
|
|
}
|
2012-01-10 03:12:01 +00:00
|
|
|
|
}
|
2012-03-24 10:53:26 +00:00
|
|
|
|
|
2012-11-29 18:42:13 +00:00
|
|
|
|
public void TogglePause()
|
|
|
|
|
{
|
2015-10-22 21:28:44 +00:00
|
|
|
|
if (State == RunState.Paused)
|
2017-04-14 19:59:01 +00:00
|
|
|
|
{
|
2015-10-22 21:28:44 +00:00
|
|
|
|
State = RunState.Running;
|
2017-04-14 19:59:01 +00:00
|
|
|
|
}
|
|
|
|
|
else if (State == RunState.Running)
|
|
|
|
|
{
|
2015-10-22 21:28:44 +00:00
|
|
|
|
State = RunState.Paused;
|
2017-04-14 19:59:01 +00:00
|
|
|
|
}
|
2012-11-29 18:42:13 +00:00
|
|
|
|
}
|
2012-01-10 03:12:01 +00:00
|
|
|
|
}
|
2011-05-06 23:08:50 +00:00
|
|
|
|
}
|