当前位置: 首页>>代码示例>>C#>>正文


C# ScriptRuntime.GetEngineByTypeName方法代码示例

本文整理汇总了C#中Microsoft.Scripting.Hosting.ScriptRuntime.GetEngineByTypeName方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptRuntime.GetEngineByTypeName方法的具体用法?C# ScriptRuntime.GetEngineByTypeName怎么用?C# ScriptRuntime.GetEngineByTypeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Scripting.Hosting.ScriptRuntime的用法示例。


在下文中一共展示了ScriptRuntime.GetEngineByTypeName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEngine

        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;
        }
开发者ID:heyxEvget,项目名称:IronPython-Debugger,代码行数:28,代码来源:MainWindow.xaml.cs

示例2: BonsaiTestClass

        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);
        }
开发者ID:eugen,项目名称:Bonsai,代码行数:17,代码来源:BonsaiTestClass.cs

示例3: Main

        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);
            }
        }
开发者ID:eugen,项目名称:Bonsai,代码行数:24,代码来源:Main.cs

示例4: PythonObject

        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);
        }
开发者ID:turkowski,项目名称:museum,代码行数:44,代码来源:PythonObject.cs

示例5: GetEngine

 /// <summary>
 /// Given a ScriptRuntime gets the ScriptEngine for IronPython.
 /// </summary>
 public static ScriptEngine/*!*/ GetEngine(ScriptRuntime/*!*/ runtime) {
     return runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:6,代码来源:Python.cs

示例6: ResetEngine

        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);

            
        }
开发者ID:nunb,项目名称:interpretation,代码行数:23,代码来源:PythonScriptHost.cs

示例7: GetEngine

 /// <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);
 }
开发者ID:jschementi,项目名称:iron,代码行数:13,代码来源:Ruby.cs

示例8: GetEngine

 ///-------------------------------------------------------------------------------------------------
 /// <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);
 }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:13,代码来源:Totem.cs

示例9: CreateEngine

        /// <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;
        }
开发者ID:simplic-systems,项目名称:simplic-dlr,代码行数:39,代码来源:IronPythonLanguage.cs


注:本文中的Microsoft.Scripting.Hosting.ScriptRuntime.GetEngineByTypeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。