/// <summary> /// Executes the command /// </summary> /// <param name="arguments">Arguments to pass to the command</param> /// <param name="target">Writable console target</param> public int Execute(IEnumerable <string> arguments, IConsoleOutput target) { try { //If the user attempt to use commands like if, while and for outside a script context if (IsCodeBlockCommand() && !(target is ScriptTargetWrapper)) { ThrowGenericError("This command can only be used in script files", ErrorCode.INVALID_CONTEXT); } Params p = new Params(arguments); GetSyntax(p).IsCorrectSyntax(this, p, true); Executed(p, target); return(0); } catch (CommandException x) { foreach (string i in x.Message.Split('\n')) { target.WriteError(i); } return(x.ErrorCode); } }
protected override void Executed(Params args, IConsoleOutput target) { if ((target is ScriptTargetWrapper)) { (target as ScriptTargetWrapper).Session.ShouldBreakDebugger = true; } else { target.WriteError("Not in scripthost"); } }
/// <summary> /// Batch executes all commands in a script file /// </summary> /// <param name="output">Output device to write to</param> public int Execute(IConsoleOutput output) { Reset(); const int STACK_LIMIT = int.MaxValue; int stackOverflow = 0; int @out = 0; //Create top level scope Scope.Push(new ScopeLoopPoint(false, new ScriptTargetWrapper(output, this))); while (Step(output, out int errOut)) { stackOverflow++; if (errOut != 0) { string descName = typeof(ErrorCode).GetFields().Where(i => (int)i.GetValue(null) == errOut).Select(i => i.Name).FirstOrDefault(); output.WriteError("===================================================="); output.WriteError("Script exited with bad error code!"); output.WriteError("* Error code: " + errOut.ToString("x3") + " " + descName); output.WriteError("* Line: " + (Index + 1).ToString("000") + " " + Lines[Index]); output.WriteError("Previous output messages might have more information"); output.WriteError("===================================================="); @out = errOut; break; } else if (stackOverflow > STACK_LIMIT) { output.WriteError("Infinite loop detected in script, aborting!!!"); @out = ErrorCode.INTERNAL_ERROR; break; } } Command.AllCommandsInternal.RemoveAll(i => i is StandardLib.Structure.Call); return(@out); }