public static void PushDepthInfo(EngineState s, int targetDepth) { while (s.PeekDepth < targetDepth) { EngineLocalState ls = s.PeekLocalState(); s.PushLocalState(ls.IsMacro, ls.RefScriptId); } }
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(); } }