예제 #1
0
 /// <summary>
 /// Executes python commands from the console.
 /// </summary>
 /// <param name="input"></param>
 /// <returns>Returns the execution results or error messages.</returns>
 public void Execute(string input)
 {
     try
     {
         if ((input != "") && ((input[input.Length - 1].ToString() == ":") || (multi != ""))) //multiline block incomplete, ask for more
         {
             multi += input + "\n";
             Console.Prompt(PromptCont, Execute);
         }
         else if (multi != "" && input == "") //execute the multiline code after block is finished
         {
             string temp = multi;             // make sure that multi is cleared, even if it returns an error
             multi = "";
             PythonEngine.Execute(temp);
             Console.WriteLine(getOutput());
             Console.Prompt(Prompt, Execute);
         }
         else // if (multi == "" && input != "") execute single line expressions or statements
         {
             PythonEngine.Execute(input);
             Console.WriteLine(Console.Chomp(getOutput()));
             Console.Prompt(Prompt, Execute);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("ERROR: " + ex.Message);
         Console.Prompt(Prompt, Execute);
     }
 }
예제 #2
0
파일: MpqConsole.cs 프로젝트: hazzik/mpqnav
 /// <summary>
 /// Creates a new MpqConsole
 /// </summary>
 public MpqConsole(MPQNav.Game1 game, SpriteFont font)
     : base((Game)game)
 {
     Console = new XnaConsoleComponent(game, font);
     game.Components.Add(Console);
     Console.Prompt(Prompt, Execute);
 }
예제 #3
0
파일: MpqConsole.cs 프로젝트: hazzik/mpqnav
 /// <summary>
 /// Executes python commands from the console.
 /// </summary>
 /// <param name="input"></param>
 /// <returns>Returns the execution results or error messages.</returns>
 public void Execute(string input)
 {
     try {
         //replace with loop that gets the names of the enums later on
         string commandCode = "Load ";
         if (input.StartsWith(commandCode, StringComparison.CurrentCultureIgnoreCase))
         {
             command.commandCode = ConsoleCommandStruct.CommandCode.Load;
             command.commandData = input.Substring(commandCode.Length);
             newCommand          = true;
             if (MyEvent != null)
             {
                 MyEvent();
             }
         }
         Console.Prompt(Prompt, Execute);
     }
     catch (Exception ex) {
         Console.WriteLine("ERROR: " + ex.Message);
         Console.Prompt(Prompt, Execute);
     }
 }
예제 #4
0
        /// <summary>
        /// Creates a new PythonInterpreter
        /// </summary>
        public PythonInterpreter(Game1 game, SpriteFont font) : base((Game)game)
        {
            this.PythonEngine = new PythonEngine();
            this.PythonOutput = new MemoryStream();
            this.PythonEngine.SetStandardOutput(PythonOutput);
            this.ASCIIEncoder = new ASCIIEncoding();

            ClrModule clr = this.PythonEngine.Import("clr") as ClrModule;

            clr.AddReference("Microsoft.Xna.Framework");
            clr.AddReference("Microsoft.Xna.Framework.Game");

            this.PythonEngine.Execute("from Microsoft.Xna.Framework import *");
            this.PythonEngine.Execute("from Microsoft.Xna.Framework.Graphics import *");
            this.PythonEngine.Execute("from Microsoft.Xna.Framework.Content import *");
            multi = "";

            Console = new XnaConsoleComponent(game, font);
            game.Components.Add(Console);
            Console.Prompt(Prompt, Execute);
            AddGlobal("Console", Console);
        }