From 860227ee661330c8fbefb3c319436a5097be3987 Mon Sep 17 00:00:00 2001 From: scepheo Date: Thu, 29 Jan 2015 14:50:09 +0000 Subject: [PATCH] LuaConsole: Actually stop and restart script upon tool restart. --- .../tools/Lua/LuaConsole.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index de8a91b052..989acce00a 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -107,9 +107,47 @@ namespace BizHawk.Client.EmuHawk { LuaImp.GuiLibrary.DrawFinish(); } + + var runningScripts = _luaList.Where(f => f.Enabled).ToList(); + + foreach (var file in runningScripts) + { + LuaImp.CallExitEvent(file.Thread); + + var functions = LuaImp.RegisteredFunctions.Where(x => x.Lua == file.Thread).ToList(); + + foreach (var function in functions) + LuaImp.RegisteredFunctions.Remove(function); + + UpdateRegisteredFunctionsDialog(); + + file.Stop(); + } LuaImp = new EmuLuaLibrary(this); InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => a.Library + "." + a.Name).ToArray()); + + foreach (var file in runningScripts) + { + try + { + file.Thread = LuaImp.SpawnCoroutine(file.Path); + file.Enabled = true; + } + catch (Exception ex) + { + if (ex is LuaScriptException) + { + file.Enabled = false; + ConsoleLog(ex.Message); + } + else + { + MessageBox.Show(ex.ToString()); + } + } + } + UpdateDialog(); }