Ejemplo n.º 1
0
        /// <summary>
        /// resumes suspended Co-routines
        /// </summary>
        /// <param name="includeFrameWaiters">should frame waiters be waken up? only use this immediately before a frame of emulation</param>
        public void ResumeScripts(bool includeFrameWaiters)
        {
            if (!_luaList.Any())
            {
                return;
            }

            if (LuaImp.GuiLibrary.SurfaceIsNull)
            {
                LuaImp.GuiLibrary.DrawNew("emu");
            }

            foreach (var lf in _luaList)
            {
                try
                {
                    LuaSandbox.Sandbox(() =>
                    {
                        if (lf.Enabled && lf.Thread != null && !lf.Paused)
                        {
                            var prohibit = lf.FrameWaiting && !includeFrameWaiters;
                            if (!prohibit)
                            {
                                // Restore this lua thread's preferred current directory
                                if (lf.CurrentDirectory != null)
                                {
                                    Environment.CurrentDirectory = PathManager.MakeAbsolutePath(lf.CurrentDirectory, null);
                                }

                                var result = LuaImp.ResumeScript(lf.Thread);
                                if (result.Terminated)
                                {
                                    LuaImp.CallExitEvent(lf.Thread);
                                    lf.Stop();
                                }

                                lf.FrameWaiting = result.WaitForFrame;

                                // If the lua thread changed its current directory, capture that here
                                lf.CurrentDirectory = Environment.CurrentDirectory;
                            }
                        }
                    }, () =>
                    {
                        lf.Enabled = false;
                        lf.Thread  = null;
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// resumes suspended Co-routines
        /// </summary>
        /// <param name="includeFrameWaiters">should frame waiters be waken up? only use this immediately before a frame of emulation</param>
        public void ResumeScripts(bool includeFrameWaiters)
        {
            if (!_luaList.Any())
            {
                return;
            }

            if (LuaImp.GuiLibrary.SurfaceIsNull)
            {
                LuaImp.GuiLibrary.DrawNew("emu");
            }

            foreach (var lf in _luaList.Where(l => l.Enabled && l.Thread != null && !l.Paused))
            {
                try
                {
                    LuaSandbox.Sandbox(lf.Thread, () =>
                    {
                        var prohibit = lf.FrameWaiting && !includeFrameWaiters;
                        if (!prohibit)
                        {
                            var result = LuaImp.ResumeScript(lf.Thread);
                            if (result.Terminated)
                            {
                                LuaImp.CallExitEvent(lf.Thread);
                                lf.Stop();
                                UpdateDialog();
                            }

                            lf.FrameWaiting = result.WaitForFrame;
                        }
                    }, () =>
                    {
                        lf.State  = LuaFile.RunState.Disabled;
                        lf.Thread = null;
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// resumes suspended Co-routines
        /// </summary>
        /// <param name="includeFrameWaiters">should frame waiters be waken up? only use this immediately before a frame of emulation</param>
        public void ResumeScripts(bool includeFrameWaiters)
        {
            if (_luaList.Any())
            {
                if (LuaImp.GuiLibrary.SurfaceIsNull)
                {
                    LuaImp.GuiLibrary.DrawNew("emu");
                }

                foreach (var lf in _luaList)
                {
                    var oldcd = Environment.CurrentDirectory;                     // Save old current directory before this lua thread clobbers it for the .net thread

                    try
                    {
                        if (lf.Enabled && lf.Thread != null && !lf.Paused)
                        {
                            var prohibit = lf.FrameWaiting && !includeFrameWaiters;
                            if (!prohibit)
                            {
                                // Restore this lua thread's preferred current directory
                                if (lf.CurrentDirectory != null)
                                {
                                    Environment.CurrentDirectory = PathManager.MakeAbsolutePath(lf.CurrentDirectory, null);
                                }

                                var result = LuaImp.ResumeScript(lf.Thread);
                                if (result.Terminated)
                                {
                                    LuaImp.CallExitEvent(lf.Thread);
                                    lf.Stop();
                                }

                                lf.FrameWaiting = result.WaitForFrame;

                                // If the lua thread changed its current directory, capture that here
                                lf.CurrentDirectory = Environment.CurrentDirectory;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is LuaScriptException || ex is LuaException)
                        {
                            lf.Enabled = false;
                            lf.Thread  = null;
                            ConsoleLog(ex.ToString());
                        }
                        else
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    finally
                    {
                        // Restore the current directory
                        Environment.CurrentDirectory = oldcd;
                    }
                }
            }
        }