public void Restart() { // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies if (IsRebootingCore) { LuaImp.Restart(Emulator.ServiceProvider); return; } if (LuaImp?.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface) { 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(lf => lf.Lua == file.Thread).ToList(); foreach (var function in functions) { LuaImp.RegisteredFunctions.Remove(function); } UpdateRegisteredFunctionsDialog(); file.Stop(); } LuaImp = new EmuLuaLibrary(Emulator.ServiceProvider); InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => a.Library + "." + a.Name).ToArray()); foreach (var file in runningScripts) { string pathToLoad = ProcessPath(file.Path); try { LuaSandbox.Sandbox(file.Thread, () => { file.Thread = LuaImp.SpawnCoroutine(pathToLoad); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); file.State = LuaFile.RunState.Running; }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } UpdateDialog(); }
public void Restart() { var runningScripts = new List <LuaFile>(); if (LuaImp != null) // Things we need to do with the existing LuaImp before we can make a new one { if (LuaImp.IsRebootingCore) { // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies LuaImp.Restart(Emulator.ServiceProvider); return; } if (LuaImp.GuiLibrary != null && LuaImp.GuiLibrary.HasLuaSurface) { LuaImp.GuiLibrary.DrawFinish(); } runningScripts = LuaImp.RunningScripts.ToList(); foreach (var file in runningScripts) { LuaImp.CallExitEvent(file); LuaImp.GetRegisteredFunctions().RemoveAll(lf => lf.Lua == file.Thread); UpdateRegisteredFunctionsDialog(); file.Stop(); } } var currentScripts = LuaImp?.ScriptList; // Temp fix for now LuaImp = OSTailoredCode.IsWindows() ? (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider) : (PlatformEmuLuaLibrary) new NotReallyLuaLibrary(); if (currentScripts != null) { LuaImp.ScriptList.AddRange(currentScripts); } InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray()); foreach (var file in runningScripts) { string pathToLoad = ProcessPath(file.Path); try { LuaSandbox.Sandbox(file.Thread, () => { LuaImp.SpawnAndSetFileThread(pathToLoad, file); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); file.State = LuaFile.RunState.Running; }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } UpdateDialog(); }