/// <summary> /// Parses a single interactive command and executes it. /// /// Returns null if successful and execution should continue, or the appropiate exit code. /// </summary> private int?RunOneInteraction() { bool continueInteraction; string s = ReadStatement(out continueInteraction); if (continueInteraction == false) { PythonContext.DispatchCommand(null); // Notify dispatcher that we're done return(0); } if (String.IsNullOrEmpty(s)) { // Is it an empty line? Console.Write(String.Empty, Style.Out); return(null); } SourceUnit su = Language.CreateSnippet(s, "<stdin>", SourceCodeKind.InteractiveCode); PythonCompilerOptions pco = (PythonCompilerOptions)Language.GetCompilerOptions(Scope); pco.Module |= ModuleOptions.ExecOrEvalCode; Action action = delegate() { try { su.Compile(pco, ErrorSink).Run(Scope); } catch (Exception e) { if (e is SystemExitException) { throw; } // Need to handle exceptions in the delegate so that they're not wrapped // in a TargetInvocationException UnhandledException(e); } }; try { PythonContext.DispatchCommand(action); } catch (SystemExitException sx) { object dummy; return(sx.GetExitCode(out dummy)); } return(null); }
public void DispatchCommand(Action command) { _context.DispatchCommand(command); }