Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public void Restart()
        {
            if (LuaImp != null && 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(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)
            {
                string pathToLoad = Path.IsPathRooted(file.Path) ? file.Path : PathManager.MakeProgramRelativePath(file.Path);                 //JUNIPIER SQUATCHBOX COMPLEX
                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();
        }
Ejemplo n.º 3
0
        public void Restart()
        {
            if (LuaImp != null && 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(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();
        }
Ejemplo n.º 4
0
        public void LoadLuaFile(string path)
        {
            var processedPath = PathManager.TryMakeRelative(path);

            if (LuaAlreadyInSession(processedPath) == false)
            {
                var luaFile = new LuaFile(string.Empty, processedPath);
                _luaList.Add(luaFile);
                LuaListView.ItemCount = _luaList.Count;
                Global.Config.RecentLua.Add(processedPath);

                if (!Global.Config.DisableLuaScriptsOnLoad)
                {
                    try
                    {
                        luaFile.Thread  = LuaImp.SpawnCoroutine(processedPath);
                        luaFile.Enabled = true;
                    }
                    catch (Exception e)
                    {
                        if (e.ToString().Substring(0, 32) == "LuaInterface.LuaScriptException:")
                        {
                            luaFile.Enabled = false;
                            ConsoleLog(e.Message);
                        }
                        else
                        {
                            MessageBox.Show(e.ToString());
                        }
                    }
                }
                else
                {
                    luaFile.Enabled = false;
                }

                luaFile.Paused = false;
            }
            else
            {
                foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad))
                {
                    file.Toggle();
                    break;
                }

                RunLuaScripts();
            }

            UpdateDialog();
        }