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


C# Hosting.ScriptRuntimeSetup类代码示例

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


ScriptRuntimeSetup类属于Microsoft.Scripting.Hosting命名空间,在下文中一共展示了ScriptRuntimeSetup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Cons_NoArg2

        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");
        }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:ScriptRuntimeSetupTest.cs

示例2: Main

    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);
        }
    }
开发者ID:numerodix,项目名称:nametrans,代码行数:35,代码来源:launcher.cs

示例3: MainPage

        public MainPage()
        {
            this.InitializeComponent();

            var setup = new ScriptRuntimeSetup();
            setup.HostType = typeof(DlrHost);
            setup.AddRubySetup();

            var runtime = Ruby.CreateRuntime(setup);
            this.engine = Ruby.GetEngine(runtime);
            this.scope = engine.CreateScope();
            this.scope.SetVariable("Main", this);

            runtime.LoadAssembly(typeof(object).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextSetOptions).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextAlignment).GetTypeInfo().Assembly);

            string outputText = @"
box = main.find_name('OutputBox')
p box.text_alignment
box.text_alignment = Windows::UI::Xaml::TextAlignment.Right
p box.text_alignment
";
            InputBox.IsSpellCheckEnabled = false;
            OutputBox.IsSpellCheckEnabled = false;
            InputBox.Document.SetText(TextSetOptions.None, outputText);
        }
开发者ID:nategreenwood,项目名称:IronLanguages,代码行数:27,代码来源:MainPage.xaml.cs

示例4: SassFileCompiler

        static SassFileCompiler()
        {
            _sassModule = new TrashStack<SassModule>(() => {
                var srs = new ScriptRuntimeSetup() {
                    HostType = typeof (ResourceAwareScriptHost),
                    //DebugMode = Debugger.IsAttached
                };
                srs.AddRubySetup();
                var runtime = Ruby.CreateRuntime(srs);
                var engine = runtime.GetRubyEngine();

                // NB: 'R:\' is a garbage path that the PAL override below will
                // detect and attempt to find via an embedded Resource file
                engine.SetSearchPaths(new[] {@"R:/lib/ironruby", @"R:/lib/ruby/1.9.1"});

                var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("SassAndCoffee.Core.lib.sass_in_one.rb"), "R:/lib/sass_in_one.rb", SourceCodeKind.File);
                var scope = engine.CreateScope();
                source.Execute(scope);
                return new SassModule {
                    PlatformAdaptationLayer = (VirtualFilePAL)runtime.Host.PlatformAdaptationLayer,
                    Engine = scope.Engine.Runtime.Globals.GetVariable("Sass"),
                    SassOption = engine.Execute(@"{:syntax => :sass, :cache_location => ""C:/""}"),
                    ScssOption = engine.Execute(@"{:syntax => :scss, :cache_location => ""C:/""}"),
                    ExecuteRubyCode = code => engine.Execute(code, scope)
                };
            });
        }
开发者ID:avonwyss,项目名称:SassAndCoffee,代码行数:27,代码来源:SassFileCompiler.cs

示例5: 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

示例6: Cons_NoArg1

        public void Cons_NoArg1()
        {
            var srs = new ScriptRuntimeSetup();
            Assert.AreEqual(0, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
        }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:ScriptRuntimeSetupTest.cs

示例7: CreateRuntime

        /*!*/
        protected override ScriptRuntime CreateRuntime()
        {
            string root = IronRubyToolsPackage.Instance.IronRubyBinPath;
            string configPath = IronRubyToolsPackage.Instance.IronRubyExecutable + ".config";
            LanguageSetup existingRubySetup = null;
            LanguageSetup rubySetup = Ruby.CreateRubySetup();

            if (File.Exists(configPath)) {
                try {
                    existingRubySetup = GetSetupByName(ScriptRuntimeSetup.ReadConfiguration(configPath), "IronRuby");
                } catch {
                    // TODO: report the error
                }
            }

            if (existingRubySetup != null) {
                var options = new RubyOptions(existingRubySetup.Options);
                rubySetup.Options["StandardLibraryPath"] = NormalizePaths(root, new[] { options.StandardLibraryPath })[0];
                rubySetup.Options["RequiredPaths"] = NormalizePaths(root, options.RequirePaths);
                rubySetup.Options["SearchPaths"] = NormalizePaths(root, options.SearchPaths);
            }

            var runtimeSetup = new ScriptRuntimeSetup();
            runtimeSetup.LanguageSetups.Add(rubySetup);
            return RemoteScriptFactory.CreateRuntime(runtimeSetup);
        }
开发者ID:TerabyteX,项目名称:main,代码行数:27,代码来源:RemoteRubyVsEvaluator.cs

示例8: RubyScriptingRuntime

        public RubyScriptingRuntime() {
            _defaultLanguageSetup = Ruby.CreateRubySetup();

            var setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(_defaultLanguageSetup);
            _scriptingRuntime = new ScriptRuntime(setup);
        }
开发者ID:anycall,项目名称:Orchard,代码行数:7,代码来源:RubyScriptingRuntime.cs

示例9: SassTransformerBase

        public SassTransformerBase(string syntaxOption)
        {
            var pal = new ResourceRedirectionPlatformAdaptationLayer();
            var srs = new ScriptRuntimeSetup
            {
                HostType = typeof(SassCompilerScriptHost),
                HostArguments = new List<object> { pal },
            };
            srs.AddRubySetup();
            var runtime = Ruby.CreateRuntime(srs);
            var engine = runtime.GetRubyEngine();

            // NB: 'R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}' is a garbage path that the PAL override will
            // detect and attempt to find via an embedded Resource file
            engine.SetSearchPaths(new List<string>
                                      {
                                          @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ironruby",
                                          @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ruby\1.9.1"
                                      });

            var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("lib.sass_in_one.rb", typeof(SassCompiler)), SourceCodeKind.File);
            var scope = engine.CreateScope();
            source.Execute(scope);

            sassCompiler = scope.Engine.Runtime.Globals.GetVariable("Sass");
            option = engine.Execute(syntaxOption);
        }
开发者ID:spooky,项目名称:flair,代码行数:27,代码来源:SassTransformerBase.cs

示例10: CreateRuntimeSetup

        /// <summary>
        /// Creates a ScriptRuntimeSetup object which includes the Python script engine with the specified options.
        /// 
        /// The ScriptRuntimeSetup object can then be additional configured and used to create a ScriptRuntime.
        /// </summary>
        /*!*/
        public static ScriptRuntimeSetup CreateRuntimeSetup(IDictionary<string, object> options)
        {
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(CreateLanguageSetup(options));

            if (options != null)
            {
                object value;
                if (options.TryGetValue("Debug", out value) &&
                    value is bool &&
                    (bool)value)
                {
                    setup.DebugMode = true;
                }

                if (options.TryGetValue("PrivateBinding", out value) &&
                    value is bool &&
                    (bool)value)
                {
                    setup.PrivateBinding = true;
                }
            }

            return setup;
        }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:31,代码来源:Totem.cs

示例11: Ruby

        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);
            }
        }
开发者ID:mattiascibien,项目名称:OpenGame.exe,代码行数:60,代码来源:Ruby.cs

示例12: GetSetupByName

 private static LanguageSetup GetSetupByName(ScriptRuntimeSetup/*!*/ setup, string/*!*/ name) {
     foreach (var languageSetup in setup.LanguageSetups) {
         if (languageSetup.Names.IndexOf(name) >= 0) {
             return languageSetup;
         }
     }
     return null;
 }
开发者ID:rpattabi,项目名称:ironruby,代码行数:8,代码来源:RemoteRubyVsEvaluator.cs

示例13: CreatePythonOnlyRuntime

        internal static ScriptRuntime CreatePythonOnlyRuntime(string[] ids, string[] exts) {
            ScriptRuntimeSetup srs = new ScriptRuntimeSetup();
            srs.LanguageSetups.Add(new LanguageSetup(
                typeof(IronPython.Runtime.PythonContext).AssemblyQualifiedName,
                "python", ids, exts
            ));

            return new ScriptRuntime(srs);
        }
开发者ID:Jirapong,项目名称:main,代码行数:9,代码来源:ScriptRuntimeTestHelper.cs

示例14: Initialize

        public void Initialize()
        {
            var setup = new ScriptRuntimeSetup();

            var typeName = typeof (NaggumLanguageContext).AssemblyQualifiedName;
            setup.LanguageSetups.Add(
                new LanguageSetup(typeName, "Naggum", new[] { "naggum" }, new[] { ".naggum" }));
            var runtime = new ScriptRuntime(setup);
            _engine = runtime.GetEngine("naggum");
        }
开发者ID:aman7,项目名称:naggum,代码行数:10,代码来源:NaggumLanguageContextTests.cs

示例15: PyControllerFactory

        static PyControllerFactory()
        {
            _setup = ScriptRuntimeSetup.ReadConfiguration();
            _runtime = new ScriptRuntime(_setup);

            _runtime.LoadAssembly(Assembly.GetExecutingAssembly());

            string path = HttpContext.Current.Server.MapPath("~/App_Data/Controllers.py");
            _runtime.GetEngine("IronPython").ExecuteFile(path, _runtime.Globals);
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:10,代码来源:PyControllerFactory.cs


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