refactor lua scripts to be more flexible

This commit is contained in:
zeromus 2012-03-23 19:44:47 +00:00
parent b64ee06a8c
commit bc3e8606a2
2 changed files with 20 additions and 17 deletions

View File

@ -20,7 +20,7 @@ namespace BizHawk.MultiClient
public EventWaitHandle LuaWait; public EventWaitHandle LuaWait;
public bool isRunning; public bool isRunning;
private int CurrentMemoryDomain = 0; //Main memory by default private int CurrentMemoryDomain = 0; //Main memory by default
List<Lua> runningThreads = new List<Lua>(); //List<Lua> runningThreads = new List<Lua>();
Lua currThread; Lua currThread;
public LuaImplementation(LuaConsole passed) public LuaImplementation(LuaConsole passed)
@ -34,7 +34,6 @@ namespace BizHawk.MultiClient
public void Close() public void Close()
{ {
lua = new Lua(); lua = new Lua();
runningThreads.Clear();
} }
public void LuaRegister(Lua lua) public void LuaRegister(Lua lua)
@ -105,13 +104,14 @@ namespace BizHawk.MultiClient
LuaLibraryList += "client." + MultiClientFunctions[i] + "\n"; LuaLibraryList += "client." + MultiClientFunctions[i] + "\n";
} }
} }
public void DoLuaFile(string File)
public Lua SpawnCoroutine(string File)
{ {
var t = lua.NewThread(); var t = lua.NewThread();
runningThreads.Add(t);
LuaRegister(t); LuaRegister(t);
var main = t.LoadFile(File); var main = t.LoadFile(File);
t.Push(main); //push main function on to stack for subsequent resuming t.Push(main); //push main function on to stack for subsequent resuming
return t;
} }
private int LuaInt(object lua_arg) private int LuaInt(object lua_arg)
@ -141,14 +141,11 @@ namespace BizHawk.MultiClient
return lua_result; return lua_result;
} }
public void ResumeScripts() public void ResumeScript(Lua script)
{ {
foreach (var t in runningThreads) currThread = script;
{ script.Resume(0);
currThread = t; currThread = null;
t.Resume(0);
currThread = null;
}
} }
public void print(string s) public void print(string s)

View File

@ -5,29 +5,35 @@ using System.Text;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
class LuaFiles class LuaFile
{ {
public string Name; public string Name;
public string Path; public string Path;
public bool Enabled; public bool Enabled;
public bool IsSeparator; public bool IsSeparator;
public LuaInterface.Lua Thread;
public LuaFiles(string path) public LuaFile(string path)
{ {
Name = ""; Name = "";
Path = path; Path = path;
Enabled = true; Enabled = true;
} }
public LuaFiles(string name, string path, bool enabled) public void Stop()
{
Enabled = false;
Thread = null;
}
public LuaFile(string name, string path)
{ {
Name = name; Name = name;
Path = path; Path = path;
Enabled = enabled;
IsSeparator = false; IsSeparator = false;
} }
public LuaFiles(bool isSeparator) public LuaFile(bool isSeparator)
{ {
IsSeparator = isSeparator; IsSeparator = isSeparator;
Name = ""; Name = "";
@ -35,7 +41,7 @@ namespace BizHawk.MultiClient
Enabled = false; Enabled = false;
} }
public LuaFiles(LuaFiles l) public LuaFile(LuaFile l)
{ {
Name = l.Name; Name = l.Name;
Path = l.Path; Path = l.Path;