Beispiel #1
0
        /// <summary>
        /// Creates a new PythonInterpreter
        /// </summary>
        public PythonInterpreter()
        {
#if !XBOX
            this.PythonEngine = new PythonEngine();
            this.PythonOutput = new MemoryStream();
            this.PythonEngine.SetStandardOutput(PythonOutput);
            this.ASCIIEncoder = new ASCIIEncoding();


            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 *");
            //this.PythonEngine.Execute("from System import *");

            multi = "";

            Console = new XnaConsoleComponent();
            XdtkResources.Console.Components.Add(Console);
            Console.Prompt(Prompt, Execute);
            AddGlobal("Console", Console);
            AddGlobal("dc", XdtkResources.Console);
            AddGlobal("game", XdtkResources.Game);

            Execute(
                @"class Tracer(GameComponent):
    def Update(self, gameTime):
        dc.Show(self.k, eval(self.v))
");
            Execute(
                @"def trace(key, value):
    a = Tracer(game)
    a.k = key
    a.v = value
    game.Components.Add(a)
");
#endif
        }
Beispiel #2
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);
        }
Beispiel #3
0
        /// <summary>
        /// Loads any extension DLLs present in sys.prefix\DLLs directory and adds references to them.
        ///
        /// This provides an easy drop-in location for .NET assemblies which should be automatically referenced
        /// (exposed via import), COM libraries, and pre-compiled Python code.
        /// </summary>
        private void InitializeExtensionDLLs()
        {
            string dir = Path.Combine(PythonContext.InitialPrefix, "DLLs");

            if (Directory.Exists(dir))
            {
                foreach (string file in Directory.EnumerateFiles(dir, "*.dll"))
                {
                    if (file.ToLower().EndsWith(".dll"))
                    {
                        try {
                            ClrModule.AddReference(PythonContext.SharedContext, new FileInfo(file).Name);
                        } catch {
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private void InitializeHome()
        {
            //string dir = Path.Combine(PythonContext_InitialPrefix, "DLLs");
            string dir = Home_Path;

            if (Directory.Exists(dir))
            {
                foreach (string file in Directory.GetFiles(dir))
                {
                    if (file.ToLower().EndsWith(".dll"))
                    {
                        try
                        {
                            ClrModule.AddReference(PythonContext_SharedContext, new FileInfo(file).Name);
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Adds a reference to an assembly
        /// </summary>
        /// <param name="name">The name of the assembly</param>
        public void AddReference(string name)
        {
#if !XBOX
            clr.AddReference(name);
#endif
        }