Represents a Dynamic Language Runtime in Hosting API. Hosting API counterpart for ScriptDomainManager.
Inheritance: System.MarshalByRefObject
        public void Create()
        {
            LogTo.Debug("PythonPacketParser created");
            _runtime = Python.CreateRuntime();

            var scriptDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            if (scriptDirectory == null)
                throw new NullReferenceException("ScriptDirectory should not be null");

            LogTo.Debug("Looking for python decoder in {0}", scriptDirectory);
            watcher = new FileSystemWatcher(scriptDirectory, "*.py");

            watcher.Changed += (sender, args) => UpdateScript(args.FullPath);
            watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
            watcher.EnableRaisingEvents = true;
            UpdateScript("interpreter.py");

            try
            {
                LogTo.Debug(InterpretPacket((new UTF8Encoding()).GetBytes("Hello from Python")));
            }
            catch (Exception e)
            {
                LogTo.WarnException("Interpreting python script threw an error", e);
            }
        }
Exemple #2
0
        public TestRuntime(Driver/*!*/ driver, TestCase/*!*/ testCase) {
            _driver = driver;
            _testName = testCase.Name;

            if (_driver.SaveToAssemblies) {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            LanguageSetup languageSetup = null;
            foreach (var language in runtimeSetup.LanguageSetups) {
                if (language.TypeName == typeof(RubyContext).AssemblyQualifiedName) {
                    languageSetup = language;
                    break;
                }
            }

            runtimeSetup.DebugMode = _driver.IsDebug;
            languageSetup.Options["InterpretedMode"] = _driver.Interpret;
            languageSetup.Options["Verbosity"] = 2;
            languageSetup.Options["Compatibility"] = testCase.Compatibility;

            _env = Ruby.CreateRuntime(runtimeSetup);
            _engine = Ruby.GetEngine(_env);
            _context = Ruby.GetExecutionContext(_engine);
        }
        public void Start()
        {
            try
            {
                _runtime = ScriptRuntime.CreateFromConfiguration();
                    // this reads from app.config for configured Dynamic Language Runtime libraries

                // now get all the file extensions of scripting types, as creatted from the Configuration
                foreach (LanguageSetup ls in _runtime.Setup.LanguageSetups)
                {
                    foreach (string fext in ls.FileExtensions)
                    {
                        _scriptingManager.RegisterLanguageExtensions(this, fext);
                    }
                }

                IEnumerable<string> lg = from setup in _runtime.Setup.LanguageSetups
                                         select setup.Names[0];
                foreach (string ln in lg)
                    _scriptingManager.RegisterLanguageNames(this, ln);

                _scopevariables = new ScopeVariables();
                    // setup the initial scopevariables that are shared by all scopes
                _librarypaths = new List<string>();
                    // list of Lib directories, or others that contain standard libraries for this script collection
            }
            catch (Exception ex)
            {
                _scriptingManager.IsScriptEngineActive = false;
                CompositionManager.Get<IExceptionReporter>().ReportHandledException(ex);
            }
        }
Exemple #4
0
        public Page()
        {
            InitializeComponent();
            string code = @"
            def function(string):
            return string.upper()";

            ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
            setup.HostType = typeof(Microsoft.Scripting.Silverlight.BrowserScriptHost);
            setup.Options["SearchPaths"] = new string[] { string.Empty };

            ScriptRuntime runtime = new ScriptRuntime(setup);
            ScriptEngine pe = Python.GetEngine(runtime);

            // load platform assemblies so you don't need to call LoadAssembly in script code.
            foreach (string name in new string[] { "mscorlib", "System", "System.Windows", "System.Windows.Browser", "System.Net" })
            {
                runtime.LoadAssembly(runtime.Host.PlatformAdaptationLayer.LoadAssembly(name));
            }

            ScriptScope scope = pe.CreateScope();
            ScriptSource source = pe.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
            source.Execute(scope);

            Func<string, string> func = scope.GetVariable<Func<string, string>>("function");

            string result = func("hello world!");
            textblock.Text = result;
        }
Exemple #5
0
        private static void LoadReferencedAssembliesIntoEnvironment(ScriptRuntime environment)
        {
            // Make sure we're running with a System.Web.dll that has the new API's we need
            UI.NoCompileCodePageParserFilter.CheckCorrectSystemWebSupport();

            // Call BuildManager.GetReferencedAssemblies(), either the one that returns an array or an ICollection,
            // depending on what's available.
            // TODO: this is a temporary workaround for bug VSWhidbey 607089.  Once fix, we should always call
            // the one that returns an ICollection.
            ICollection referencedAssemblies = null;
            GetReferencedAssembliesReturnCollection getReferencedAssembliesCollection =
                (GetReferencedAssembliesReturnCollection)GetGetReferencedAssembliesDelegate(
                    typeof(GetReferencedAssembliesReturnCollection));
            if (getReferencedAssembliesCollection != null) {
                referencedAssemblies = getReferencedAssembliesCollection();
            } else {
                GetReferencedAssembliesReturnArray getReferencedAssembliesArray =
                    (GetReferencedAssembliesReturnArray)GetGetReferencedAssembliesDelegate(
                        typeof(GetReferencedAssembliesReturnArray));
                Debug.Assert(getReferencedAssembliesArray != null);
                if (getReferencedAssembliesArray != null) {
                    referencedAssemblies = getReferencedAssembliesArray();
                }
            }

            if (referencedAssemblies != null) {
                // Load all the BuildManager assemblies into the engine
                foreach (Assembly a in referencedAssemblies) {
                    environment.LoadAssembly(a);
                }
            }
        }
 internal PythonConverser(Socket socket, IEnumerable<NameBinding> nameBindings)
     : base(socket)
 {
     _ScriptRuntime = IronPython.Hosting.Python.CreateRuntime();
     InitialiseScriptRuntime(socket);
     BindScriptScopeNames(nameBindings);
 }
        public ScriptEngine GetEngine()
        {
            if (_engine != null)
                return _engine;
            _engine = Python.CreateEngine();

            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.DebugMode = true;
            setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
            ScriptRuntime runtime = new ScriptRuntime(setup);
            _engine = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);

            _engine.Runtime.IO.SetOutput(_stream, Encoding.UTF8);
            _engine.Runtime.IO.SetErrorOutput(_stream, Encoding.UTF8);
            string path = Environment.CurrentDirectory;
            string ironPythonLibPath = string.Format(@"{0}\IronPythonLib.zip", path);
            var paths = _engine.GetSearchPaths() as List<string> ?? new List<string>();
            paths.Add(path);
            paths.Add(ironPythonLibPath);
            path = Environment.GetEnvironmentVariable("IRONPYTHONPATH");
            if (!string.IsNullOrEmpty(path))
            {
                var pathStrings = path.Split(';');
                paths.AddRange(pathStrings.Where(p => p.Length > 0));
            }
            _engine.SetSearchPaths(paths.ToArray());
            return _engine;
        }
        static void Main(string[] args)
        {
            try {

                ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
                ScriptRuntime runtime = new ScriptRuntime(setup);
                runtime.GetEngine("Python").Execute("print \"Hello, Hosted Script World!\"");
                //runtime.ExecuteFile(PYTHON_FILE);

                //ScriptScope scope = runtime.GetEngine("Python").CreateScope();
                //scope.SetVariable("name", "John Zablocki");
                #region func
                //Func<string, string> reverse = (s) => {
                //        string reversed = "";
                //        for (int i = s.Length - 1; i >= 0; i--) {
                //            reversed += s[i];
                //        }
                //        return reversed;
                //    };
                //scope.SetVariable("reverse", reverse);
                #endregion
                //runtime.GetEngine("Python").ExecuteFile(PYTHON_FILE, scope);

            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #9
0
        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType = typeof(RhoHost);

            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"] = 0;
            languageSetup.Options["Verbosity"] = 2;

            m_runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            m_engine = IronRuby.Ruby.GetEngine(m_runtime);
            m_context = (RubyContext)Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_engine);

            m_context.ObjectClass.SetConstant("RHO_WP7", 1);
            m_context.Loader.LoadAssembly("RhoRubyLib", "rho.rubyext.rubyextLibraryInitializer", true, true);

            System.Collections.ObjectModel.Collection<string> paths = new System.Collections.ObjectModel.Collection<string>();
            paths.Add("lib");
            paths.Add("apps/app");
            m_engine.SetSearchPaths(paths);
        }
Exemple #10
0
        public TestRuntime(Driver/*!*/ driver, TestCase/*!*/ testCase) {
            _driver = driver;
            _testName = testCase.Name;

            if (testCase.Options.NoRuntime) {
                return;
            }

            if (_driver.SaveToAssemblies) {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = runtimeSetup.AddRubySetup();

            runtimeSetup.DebugMode = _driver.IsDebug;
            runtimeSetup.PrivateBinding = testCase.Options.PrivateBinding;
            languageSetup.Options["NoAdaptiveCompilation"] = _driver.NoAdaptiveCompilation;
            languageSetup.Options["Verbosity"] = 2;
            languageSetup.Options["Compatibility"] = testCase.Options.Compatibility;

            _runtime = Ruby.CreateRuntime(runtimeSetup);
            _engine = Ruby.GetEngine(_runtime);
            _context = Ruby.GetExecutionContext(_engine);
        }
        public void Cons_NoArg2()
        {
            var srs = new ScriptRuntimeSetup();
            var sr = new ScriptRuntime(srs);

            Assert.Fail("shouldn't be able to create a runtime without any langsetups");
        }
        public void Cons_NoArg1()
        {
            var srs = new ScriptRuntimeSetup();
            Assert.AreEqual(0, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
        }
Exemple #13
0
 public DlrContext(ScriptRuntime runtime, IPathProvider pathProvider, string routesPath)
 {
     //_routesPath = routesPath;
     Runtime = runtime;
     PathProvider = pathProvider;
     //Initialize();
 }
Exemple #14
0
        public Ruby()
        {
            //Setup the script engine runtime
            var setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(
                new LanguageSetup(
                    "IronRuby.Runtime.RubyContext, IronRuby",
                    "IronRuby 1.0",
                    new[] { "IronRuby", "Ruby", "rb" },
                    new[] { ".rb" }));
            setup.DebugMode = true;
            
            //Create the runtime, engine, and scope
            runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, setup);
            engine = runtime.GetEngine("Ruby");
            scope = engine.CreateScope();

            try
            {
                engine.Execute(@"$RGSS_VERSION = " + Program.GetRuntime().GetRGSSVersion(), scope);
                engine.Execute(@"$GAME_DIRECTORY = '" + Program.GetRuntime().GetResourcePaths()[0].Replace(@"\", @"\\") + @"'", scope);
                engine.Execute(@"$GAME_OS_WIN = " + Program.GetRuntime().IsWindowsOS().ToString().ToLower(), scope);
            }
            catch (Exception e)
            {
                Program.Error(e.Message);
            }

            //Load system internals and our Ruby internals
            Console.WriteLine("Loading system");
            //engine.Execute(System.Text.Encoding.UTF8.GetString(Properties.Resources.System), scope);
            string script = System.Text.Encoding.UTF8.GetString(Properties.Resources.System);
            script = script.Substring(1);  //fix for a weird character that shouldn't be there o.O
            Eval(script);

            //Load the adaptable RPG datatypes
            script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG);
            script = script.Substring(1);
            Eval(script);

            //Load the version appropriate RPG datatypes
            if (Program.GetRuntime().GetRGSSVersion() == 1)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG1);
                script = script.Substring(1);
                Eval(script);
            }
            if (Program.GetRuntime().GetRGSSVersion() == 2)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG2);
                script = script.Substring(1);
                Eval(script);
            }
            if (Program.GetRuntime().GetRGSSVersion() == 3)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG3);
                script = script.Substring(1);
                Eval(script);
            }
        }
Exemple #15
0
        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType = typeof(RhoHost);

            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"] = 0;
            languageSetup.Options["Verbosity"] = 2;

            m_runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            m_engine = IronRuby.Ruby.GetEngine(m_runtime);
            m_context = (RubyContext)Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_engine);

            m_context.ObjectClass.SetConstant("RHO_WP7", 1);
            m_context.ObjectClass.AddMethod(m_context, "__rhoGetCallbackObject", new RubyLibraryMethodInfo(
                new[] { LibraryOverload.Create(new Func<System.Object, System.Int32, System.Object>(RhoKernelOps.__rhoGetCallbackObject), false, 0, 0) },
                RubyMethodVisibility.Public,
                m_context.ObjectClass
            ));
            m_context.Loader.LoadAssembly("RhoRubyLib", "rho.rubyext.rubyextLibraryInitializer", true, true);

            System.Collections.ObjectModel.Collection<string> paths = new System.Collections.ObjectModel.Collection<string>();
            paths.Add("lib");
            paths.Add("apps/app");
            m_engine.SetSearchPaths(paths);
        }
Exemple #16
0
 /// <summary>
 /// Creates instances of the Ruby engine and Ruby scope
 /// </summary>
 public static void CreateRuntime()
 {
     _rubyRuntime = IronRuby.Ruby.CreateRuntime();
       _rubyEngine = IronRuby.Ruby.GetEngine(_rubyRuntime);
       _rubyScope = _rubyEngine.CreateScope();
       _rubyEngine.Execute(@"load_assembly 'IronRuby.Libraries', 'IronRuby.StandardLibrary.Zlib'", _rubyScope);
 }
        public RubyScriptingRuntime() {
            _defaultLanguageSetup = Ruby.CreateRubySetup();

            var setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(_defaultLanguageSetup);
            _scriptingRuntime = new ScriptRuntime(setup);
        }
Exemple #18
0
    static void Main(string[] args)
    {
        // set path for dynamic assembly loading
        AppDomain.CurrentDomain.AssemblyResolve +=
            new ResolveEventHandler(ResolveAssembly);

        string path = System.IO.Path.Combine(exe_path, py_path);
        pyscript = System.IO.Path.Combine(path, pyscript);
        pyscript = System.IO.Path.GetFullPath(pyscript); // normalize

        // get runtime
        ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();

        LanguageSetup language = Python.CreateLanguageSetup(null);
        language.Options["Debug"] = true;
        scriptRuntimeSetup.LanguageSetups.Add(language);

        ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);

        // set sys.argv
        SetPyEnv(runtime, pyscript, args);

        // get engine
        ScriptScope scope = runtime.CreateScope();
        ScriptEngine engine = runtime.GetEngine("python");

        ScriptSource source = engine.CreateScriptSourceFromFile(pyscript);
        source.Compile();

        try {
            source.Execute(scope);
        } catch (IronPython.Runtime.Exceptions.SystemExitException e) {
            Console.WriteLine(e.StackTrace);
        }
    }
Exemple #19
0
 public Ability()
 {
     DescriptionArgs = new List<string>();
     ExperienceTable = new List<int>();
     Properties = new PropertyNotificationObject();
     Properties.PropertyChanged += PropertyChanged;
     _runtime = Scripting.Instance.Runtime;
 }
Exemple #20
0
        public Item()
        {
            _runtime = Scripting.Instance.Runtime;

            Description = new Description();
            Properties = new PropertyNotificationObject();
            Properties.PropertyChanged += PropertyChanged;
        }
Exemple #21
0
 public static Action<HappyRuntimeContext> CompileModule(string filename)
 {
     ScriptRuntime runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration());
     Microsoft.Scripting.Hosting.ScriptEngine engine = runtime.GetEngine("ht");
     ScriptScope globals = engine.CreateScope();
     var scriptSource = engine.CreateScriptSourceFromString(readFile(filename), filename, SourceCodeKind.File);
     return scriptSource.Execute(globals);
 }
        private void startPythonEngine()
        {
            m_engine = Python.CreateEngine();
            m_runtime = m_engine.Runtime;
            m_scope = m_engine.CreateScope();

            m_runtime.LoadAssembly(GetType().Assembly);
        }
Exemple #23
0
        private void InitializeRuntime(bool debugMode) {
            RuntimeSetup = CreateRuntimeSetup();
            RuntimeSetup.DebugMode = debugMode;
            RuntimeSetup.Options["SearchPaths"] = new string[] { String.Empty };

            Runtime = new ScriptRuntime(RuntimeSetup);
            LoadDefaultAssemblies();
        }
Exemple #24
0
 public Effect()
 {
     Description = new Description();
     Events = new CombatEvents();
     Properties = new PropertyNotificationObject();
     Properties.PropertyChanged += PropertyChanged;
     _runtime = Scripting.Instance.Runtime;
 }
        public void register()
        {
            engine = Python.CreateEngine();
            scope = null;
            runtime = engine.Runtime;

            scope = runtime.CreateScope();
        }
Exemple #26
0
        public PyMarshaler()
        {
            _engine = Python.CreateEngine();
            _runtime = _engine.Runtime;

            ICollection<string> searchPaths = _engine.GetSearchPaths();
            searchPaths.Add("PyScripts");
            _engine.SetSearchPaths(searchPaths);
        }
Exemple #27
0
		public Interpreter()
		{
			pyEngine = Python.CreateEngine();
			pyRuntime = pyEngine.Runtime;
			pyScope = pyEngine.CreateScope();
			var paths = pyEngine.GetSearchPaths();
			paths.Add(Path.Combine(Logic.Client.ExecutingDirectory, "Client", "LIB"));
			pyEngine.SetSearchPaths(paths);
		}
        public IronPythonScriptEngine()
        {
            runtime = engine.Runtime;
            runtime.LoadAssembly(Assembly.GetAssembly(typeof(Mogre.Vector3)));
            scope = runtime.CreateScope();

            // install built-in scripts
            install(new Script(builtin));
        }
Exemple #29
0
        public Engine(TextBox textbox)
        {
            _engine = Python.CreateEngine();
            _runtime = _engine.Runtime;
            _box = textbox;

            SetStreams();
            string rootDir = AddAssemblies();
            LoadPlugins(rootDir);
        }
        public void Configuration_MutateAndCheck()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python });

            var sr = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile));
            var config1 = sr.Setup;
            config1 = null;

            Assert.IsNotNull(sr.Setup);
        }
Exemple #31
0
    static void Main(string[] args)
    {
        // set path for dynamic assembly loading
        AppDomain.CurrentDomain.AssemblyResolve +=
            new ResolveEventHandler(ResolveAssembly);


        string path = System.IO.Path.Combine(exe_path, py_path);

        pyscript = System.IO.Path.Combine(path, pyscript);
        pyscript = System.IO.Path.GetFullPath(pyscript);         // normalize

        // get runtime
        ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();

        LanguageSetup language = Python.CreateLanguageSetup(null);

        language.Options["Debug"] = true;
        scriptRuntimeSetup.LanguageSetups.Add(language);

        ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);

        // set sys.argv
        SetPyEnv(runtime, pyscript, args);

        // get engine
        ScriptScope  scope  = runtime.CreateScope();
        ScriptEngine engine = runtime.GetEngine("python");

        ScriptSource source = engine.CreateScriptSourceFromFile(pyscript);

        source.Compile();

        try {
            source.Execute(scope);
        } catch (IronPython.Runtime.Exceptions.SystemExitException e) {
            Console.WriteLine(e.StackTrace);
        }
    }