GetEngineByTypeName() public method

public GetEngineByTypeName ( string assemblyQualifiedTypeName ) : ScriptEngine
assemblyQualifiedTypeName string
return ScriptEngine
コード例 #1
0
        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;
        }
コード例 #2
0
ファイル: BonsaiTestClass.cs プロジェクト: eugen/Bonsai
        public BonsaiTestClass()
        {
            ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup() {
                DebugMode = true,
                LanguageSetups = {
                      new LanguageSetup(
                        typeof(BonsaiContext).AssemblyQualifiedName,
                        "Bonsai",
                        new string[] {"Bonsai"},
                        new string[] {".bon"})
                }
            };

            ScriptRuntime runtime = new ScriptRuntime(runtimeSetup);
            ScriptScope global = runtime.CreateScope();
            scriptEngineInstance = runtime.GetEngineByTypeName(typeof(BonsaiContext).AssemblyQualifiedName);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: eugen/Bonsai
        public static void Main(string[] args)
        {
            ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup() {
                DebugMode = true,
                LanguageSetups = {
                      new LanguageSetup(
                        typeof(BonsaiContext).AssemblyQualifiedName,
                        "Bonsai",
                        new string[] {"Bonsai"},
                        new string[] {".bon"})
                }
            };

            ScriptRuntime runtime = new ScriptRuntime(runtimeSetup);
            ScriptScope global = runtime.CreateScope();
            ScriptEngine engine = runtime.GetEngineByTypeName(typeof(BonsaiContext).AssemblyQualifiedName);

            var result = engine.Execute(File.ReadAllText("Test.bon"));
            string line;
            while((line = Console.ReadLine()).Length > 0) {
                result = engine.Execute(line);
                Console.WriteLine(result);
            }
        }
コード例 #4
0
ファイル: PythonObject.cs プロジェクト: turkowski/museum
        public PythonObject(string[] args)
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            ConsoleHostOptions options = new ConsoleHostOptions();
            _optionsParser = new ConsoleHostOptionsParser(options, runtimeSetup);

            string provider = GetLanguageProvider(runtimeSetup);

            LanguageSetup languageSetup = null;
            foreach (LanguageSetup language in runtimeSetup.LanguageSetups) {
                if (language.TypeName == provider) {
                    languageSetup = language;
                }
            }
            if (languageSetup == null) {
                // the language doesn't have a setup -> create a default one:
                languageSetup = new LanguageSetup(Provider.AssemblyQualifiedName, Provider.Name);
                runtimeSetup.LanguageSetups.Add(languageSetup);
            }

            // inserts search paths for all languages (/paths option):
            InsertSearchPaths(runtimeSetup.Options, Options.SourceUnitSearchPaths);

            _languageOptionsParser = new OptionsParser<ConsoleOptions>();

            try {
                _languageOptionsParser.Parse(Options.IgnoredArgs.ToArray(), runtimeSetup, languageSetup, PlatformAdaptationLayer.Default);
            } catch (InvalidOptionException e) {
                Console.Error.WriteLine(e.Message);
            }

            _runtime = new ScriptRuntime(runtimeSetup);

            try {
                _engine = _runtime.GetEngineByTypeName(provider);
            } catch (Exception e) {
                Console.Error.WriteLine(e.Message);
            }
            _runtime.LoadAssembly(System.Reflection.Assembly.GetExecutingAssembly());
            _runtime.LoadAssembly(provider.GetType().Assembly);
            _runtime.LoadAssembly(PythonStringIO.StringIO().GetType().Assembly);
            _scope= _engine.CreateScope();
            RunCommandLine(args);
        }
コード例 #5
0
ファイル: Python.cs プロジェクト: jxnmaomao/ironruby
 /// <summary>
 /// Given a ScriptRuntime gets the ScriptEngine for IronPython.
 /// </summary>
 public static ScriptEngine/*!*/ GetEngine(ScriptRuntime/*!*/ runtime) {
     return runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
 }
コード例 #6
0
        public void ResetEngine(bool debugmode = false)
        {
            if(_python != null)
                 _python.Runtime.Shutdown();

            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.DebugMode = debugmode;
            setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
            ScriptRuntime runtime = new ScriptRuntime(setup);

            _python = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
            LoadAssembly(typeof(Prefab.Bitmap).Assembly);
            LoadAssembly(typeof(PrefabUtils.PathDescriptor).Assembly);

            if(_consoleOutput == null)
                 _consoleOutput = new MemoryStream();
            _python.Runtime.IO.SetOutput(_consoleOutput, Encoding.Default);
            // _python.Runtime.GetClrModule().GetVariable("AddReference")("Prefab");
            //_python = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
            //Instance = new PythonScriptHost(false);

            
        }
コード例 #7
0
ファイル: Ruby.cs プロジェクト: jschementi/iron
 /// <summary>
 /// Retrieves an IronRuby engine from a given script runtime.
 /// </summary>
 /// <param name="runtime">The runtime to get the engine from.</param>
 /// <returns>An IronRuby engine from the specified runtime.</returns>
 /// <exception cref="ArgumentException">
 /// The <paramref name="runtime"/> is not set up to run IronRuby. 
 /// The <see cref="ScriptRuntimeSetup"/> doesn't contain IronRuby's <see cref="ScriptLanguageSetup"/>.
 /// </exception>
 public static ScriptEngine/*!*/ GetEngine(ScriptRuntime/*!*/ runtime) {
     ContractUtils.RequiresNotNull(runtime, "runtime");
     return runtime.GetEngineByTypeName(typeof(RubyContext).AssemblyQualifiedName);
 }
コード例 #8
0
ファイル: Totem.cs プロジェクト: Alxandr/IronTotem-3.0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>   Given a ScriptRuntime gets the ScriptEngine for IronTotem. </summary>
 ///
 /// <remarks>   Aleksander, 14.04.2013. </remarks>
 ///
 /// <param name="runtime">  The runtime. </param>
 ///
 /// <returns>   The engine. </returns>
 ///-------------------------------------------------------------------------------------------------
 public static ScriptEngine GetEngine(ScriptRuntime runtime)
 {
     return runtime.GetEngineByTypeName(typeof(TotemContext).AssemblyQualifiedName);
 }
コード例 #9
0
        /// <summary>
        /// Create new scripting engine
        /// </summary>
        /// <param name="runtime">Instance of the current runtime enviroement</param>
        /// <returns>Instance of IP script engine</returns>
        public ScriptEngine CreateEngine(ScriptRuntime runtime)
        {
            scriptEngine = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);

            // Override import functionality
            ScriptScope scope = IronPython.Hosting.Python.GetBuiltinModule(scriptEngine);
            scope.SetVariable("__import__", new ImportDelegate(ResolveImport));

            var sysScope = scriptEngine.GetSysModule();

            List path_hooks = sysScope.GetVariable("path_hooks");

            // Disable zipimporter if needed
            for (int i = 0; i < path_hooks.Count; i++)
            {
                if (path_hooks.ElementAt(i) != null)
                {
                    PythonType type = path_hooks.ElementAt(i) as PythonType;
                    string name = PythonType.Get__name__(type);

                    if (name == "zipimporter" && EnableZipImporter == false)
                    {
                        path_hooks.RemoveAt(i);
                    }
                }
            }

            PythonType genericimporter = DynamicHelpers.GetPythonType(new GenericImportModule.genericimporter());
            path_hooks.Add(genericimporter);

            sysScope.SetVariable("path_hooks", path_hooks);

            return scriptEngine;
        }