BizHawk/BizHawk.Client.Common/lua/LuaFile.cs

87 lines
1.7 KiB
C#
Raw Normal View History

namespace BizHawk.Client.Common
2011-05-06 23:08:50 +00:00
{
2013-10-28 13:48:17 +00:00
public class LuaFile
{
public LuaFile(string path)
{
2017-05-10 11:45:23 +00:00
Name = "";
Path = path;
State = RunState.Running;
FrameWaiting = false;
}
2011-05-06 23:08:50 +00:00
public LuaFile(string name, string path)
{
Name = name;
Path = path;
IsSeparator = false;
// 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);
}
2011-05-07 00:07:27 +00:00
2017-05-18 16:36:38 +00:00
private LuaFile(bool isSeparator)
{
IsSeparator = isSeparator;
2017-05-10 11:45:23 +00:00
Name = "";
Path = "";
State = RunState.Disabled;
}
2011-05-06 23:08:50 +00:00
2017-05-18 16:36:38 +00:00
public static LuaFile SeparatorInstance => new LuaFile(true);
public string Name { get; set; }
2017-05-18 16:36:38 +00:00
public string Path { get; }
public bool Enabled => State != RunState.Disabled;
public bool Paused => State == RunState.Paused;
2017-05-18 16:36:38 +00:00
public bool IsSeparator { get; }
public NLua.Lua Thread { get; set; }
public bool FrameWaiting { get; set; }
public string CurrentDirectory { get; set; }
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
{
State = RunState.Disabled;
//if(NLua.Lua.WhichLua == "NLua")
Thread.GetTable("keepalives")[Thread] = null;
2013-10-28 13:48:17 +00:00
Thread = null;
}
2011-05-06 23:08:50 +00:00
public void Toggle()
{
if (State == RunState.Paused)
{
State = RunState.Running;
}
else if (State == RunState.Disabled)
{
State = RunState.Running;
FrameWaiting = false;
}
else
{
State = RunState.Disabled;
}
}
public void TogglePause()
{
if (State == RunState.Paused)
{
State = RunState.Running;
}
else if (State == RunState.Running)
{
State = RunState.Paused;
}
}
}
2011-05-06 23:08:50 +00:00
}