diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index 430e947040..6d04cbc817 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -20,7 +20,7 @@ namespace BizHawk.MultiClient public EventWaitHandle LuaWait; public bool isRunning; private int CurrentMemoryDomain = 0; //Main memory by default - List runningThreads = new List(); + //List runningThreads = new List(); Lua currThread; public LuaImplementation(LuaConsole passed) @@ -34,7 +34,6 @@ namespace BizHawk.MultiClient public void Close() { lua = new Lua(); - runningThreads.Clear(); } public void LuaRegister(Lua lua) @@ -105,13 +104,14 @@ namespace BizHawk.MultiClient LuaLibraryList += "client." + MultiClientFunctions[i] + "\n"; } } - public void DoLuaFile(string File) + + public Lua SpawnCoroutine(string File) { var t = lua.NewThread(); - runningThreads.Add(t); LuaRegister(t); var main = t.LoadFile(File); t.Push(main); //push main function on to stack for subsequent resuming + return t; } private int LuaInt(object lua_arg) @@ -141,14 +141,11 @@ namespace BizHawk.MultiClient return lua_result; } - public void ResumeScripts() + public void ResumeScript(Lua script) { - foreach (var t in runningThreads) - { - currThread = t; - t.Resume(0); - currThread = null; - } + currThread = script; + script.Resume(0); + currThread = null; } public void print(string s) diff --git a/BizHawk.MultiClient/tools/LuaFiles.cs b/BizHawk.MultiClient/tools/LuaFiles.cs index f700efdc2c..98c4eae5ed 100644 --- a/BizHawk.MultiClient/tools/LuaFiles.cs +++ b/BizHawk.MultiClient/tools/LuaFiles.cs @@ -5,29 +5,35 @@ using System.Text; namespace BizHawk.MultiClient { - class LuaFiles + class LuaFile { public string Name; public string Path; public bool Enabled; public bool IsSeparator; + public LuaInterface.Lua Thread; - public LuaFiles(string path) + public LuaFile(string path) { Name = ""; Path = path; 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; Path = path; - Enabled = enabled; IsSeparator = false; } - public LuaFiles(bool isSeparator) + public LuaFile(bool isSeparator) { IsSeparator = isSeparator; Name = ""; @@ -35,7 +41,7 @@ namespace BizHawk.MultiClient Enabled = false; } - public LuaFiles(LuaFiles l) + public LuaFile(LuaFile l) { Name = l.Name; Path = l.Path;