示例#1
0
        public static List <LogInfo> DebugCmd(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();
            CodeInfo_Debug info = cmd.Info.Cast <CodeInfo_Debug>();

            switch (info.Type)
            {
            case DebugType.Breakpoint:
            {
                DebugInfo_Breakpoint subInfo = info.SubInfo.Cast <DebugInfo_Breakpoint>();

                bool pause = true;
                if (subInfo.Cond != null)
                {
                    pause = CommandBranch.EvalBranchCondition(s, subInfo.Cond, out _);
                }

                if (pause)
                {
                    logs.Add(new LogInfo(LogState.Info, "Breakpoint triggered"));

                    // Activate debugger window
                    // DebugViewModel

                    // Wait until user closes debugger window
                }
            }
            break;

            default:     // Error
                throw new InternalException("Internal Logic Error at CommandDebug");
            }

            return(logs);
        }
示例#2
0
        public static void Macro(EngineState s, CodeCommand cmd)
        {
            CodeInfo_Macro info = cmd.Info.Cast <CodeInfo_Macro>();

            bool        isGlobal;
            CodeCommand macroCmd;

            if (s.Macro.GlobalDict.ContainsKey(info.MacroType))
            {
                macroCmd         = s.Macro.GlobalDict[info.MacroType];
                macroCmd.RawCode = cmd.RawCode;
                isGlobal         = true;
            }
            else if (s.Macro.LocalDict.ContainsKey(info.MacroType))
            {
                macroCmd         = s.Macro.LocalDict[info.MacroType];
                macroCmd.RawCode = cmd.RawCode;
                isGlobal         = false;
            }
            else
            {
                s.Logger.BuildWrite(s, new LogInfo(LogState.Error, $"Invalid Command [{info.MacroType}]", cmd, s.CurDepth));
                return;
            }

            Dictionary <int, string> paramDict = new Dictionary <int, string>();

            for (int i = 0; i < info.Args.Count; i++)
            {
                paramDict[i + 1] = StringEscaper.ExpandSectionParams(s, info.Args[i]);
            }

            s.CurSectionInParams = paramDict;
            s.Logger.BuildWrite(s, new LogInfo(LogState.Info, $"Executing Command [{info.MacroType}]", cmd, s.CurDepth));

            // Backup and set EngineState values
            int realScriptIdBackup = s.RefScriptId;

            if (isGlobal)
            {
                s.RefScriptId = s.Logger.BuildRefScriptWrite(s, macroCmd.Section.Script);
            }
            s.InMacro = true;

            CommandBranch.RunExec(s, macroCmd, true);

            // Restore and reset EngineState values
            s.RefScriptId = realScriptIdBackup;
            s.InMacro     = false;
        }
示例#3
0
        public static void Macro(EngineState s, CodeCommand cmd)
        {
            CodeInfo_Macro info = cmd.Info.Cast <CodeInfo_Macro>();

            CodeCommand macroCmd;

            if (s.Macro.GlobalDict.ContainsKey(info.MacroType))
            {
                macroCmd = s.Macro.GlobalDict[info.MacroType];
            }
            else if (s.Macro.LocalDict.ContainsKey(info.MacroType))
            {
                macroCmd = s.Macro.LocalDict[info.MacroType];
            }
            else
            {
                throw new ExecuteException($"Invalid command [{info.MacroType}]");
            }

            Dictionary <int, string> paramDict = new Dictionary <int, string>();

            for (int i = 0; i < info.Args.Count; i++)
            {
                paramDict[i + 1] = StringEscaper.Preprocess(s, info.Args[i]);
            }

            s.CurSectionInParams = paramDict;
            s.Logger.BuildWrite(s, new LogInfo(LogState.Info, $"Executing command [{info.MacroType}]", cmd, s.PeekDepth));

            if (macroCmd.Type == CodeType.Run || macroCmd.Type == CodeType.RunEx || macroCmd.Type == CodeType.Exec)
            {
                CommandBranch.RunExec(s, macroCmd, new CommandBranch.RunExecOptions
                {
                    PreserveCurrentParams = true,
                    IsMacro = true,
                });
            }
            else
            {
                s.PushLocalState(true, s.Logger.BuildRefScriptWrite(s, macroCmd.Section.Script, true));
                Engine.ExecuteCommand(s, macroCmd);
                s.PopLocalState();
            }
        }