private void RunLuaScripts() { foreach (var file in LuaImp.ScriptList.Where(s => !s.IsSeparator)) { if (!file.Enabled && file.Thread == null) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = ProcessPath(file.Path); LuaImp.SpawnAndSetFileThread(file.Path, file); LuaSandbox.CreateSandbox(file.Thread, Path.GetDirectoryName(pathToLoad)); }, () => { file.State = LuaFile.RunState.Disabled; }); } catch (Exception e) { MessageBox.Show(e.ToString()); } } else { file.Stop(); } } }
private void EnableLuaFile(LuaFile item) { try { LuaSandbox.Sandbox(null, () => { string pathToLoad = Path.IsPathRooted(item.Path) ? item.Path : PathManager.MakeProgramRelativePath(item.Path); LuaImp.SpawnAndSetFileThread(pathToLoad, item); LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(pathToLoad)); }, () => { item.State = LuaFile.RunState.Disabled; }); // Shenanigans // We want any gui.text messages from a script to immediately update even when paused GlobalWin.OSD.ClearGUIText(); GlobalWin.Tools.UpdateToolsAfter(); LuaImp.EndLuaDrawing(); LuaImp.StartLuaDrawing(); } catch (IOException) { ConsoleLog($"Unable to access file {item.Path}"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
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(); }