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


C# ScriptRuntime.GetEngine方法代码示例

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


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

示例1: Main

        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);
            }
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:27,代码来源:Program.cs

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

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

示例4: HAPITestBase

        protected HAPITestBase() {
            
            var ses = CreateSetup();
            ses.HostType = typeof(TestHost);
            _runtime = new ScriptRuntime(ses);
            _remoteRuntime = ScriptRuntime.CreateRemote(TestHelpers.CreateAppDomain("Alternate"), ses);

            _runTime = _runtime;// _remoteRuntime;

            _PYEng = _runTime.GetEngine("py");
            _RBEng = _runTime.GetEngine("rb");

            SetTestLanguage();
            
            _defaultScope = _runTime.CreateScope();
            _codeSnippets = new PreDefinedCodeSnippets();
        }
开发者ID:rifraf,项目名称:iron,代码行数:17,代码来源:HAPITestBase.cs

示例5: CompileModule

 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);
 }
开发者ID:dlurton,项目名称:Happy,代码行数:8,代码来源:HappyCompiler.cs

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

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

示例8: ReadConfiguration_1Lang

        public void ReadConfiguration_1Lang() {
            string configFile = GetTempConfigFile(new[]{LangSetup.Python});

            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);

            var pythonEngine = sr.GetEngine("py");
            Assert.IsTrue(pythonEngine.IsValidPythonEngine());
        }
开发者ID:Jirapong,项目名称:main,代码行数:12,代码来源:ScriptRuntimeSetupTest.cs

示例9: Engine

        /// <summary>
        /// Initialises an instance
        /// </summary>
        /// <param name="languageSetup">Scripting language configuration object</param>
        /// <param name="enableDebugging">Indicates whether script debugging should be enabled</param>
        public Engine(LanguageSetup languageSetup, bool enableDebugging)
        {
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(languageSetup);
            setup.DebugMode = enableDebugging;

            var runtime = new ScriptRuntime(setup);
            var engine = runtime.GetEngine(setup.LanguageSetups[0].Names[0]);

            _engine = engine;
            _scope = _engine.CreateScope();
        }
开发者ID:rablewis,项目名称:NuScript,代码行数:17,代码来源:Engine.cs

示例10: pythonEngine

        public pythonEngine(String pythonFilename)
        {
            // Create a new engine and scope
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null));
            ScriptRuntime runtime = new ScriptRuntime(setup);
            runtime.IO.RedirectToConsole();
            _engine = runtime.GetEngine("IronPython");
            _scope = _engine.CreateScope();

            loadPythonFile(pythonFilename);
        }
开发者ID:randomdude,项目名称:Lavalamp,代码行数:12,代码来源:pythonEngine.cs

示例11: Configuration_MutateAndCheck3

        public void Configuration_MutateAndCheck3()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python });

            var sr = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile));
            var eng = sr.GetEngine("py");

            var config = eng.Setup;
            config = null;

            Assert.IsNotNull(eng.Setup);
        }
开发者ID:TerabyteX,项目名称:main,代码行数:12,代码来源:ScriptRuntimeSetupTest.cs

示例12: ReadConfiguration_All4Langs

        public void ReadConfiguration_All4Langs() {
            var srs = ScriptRuntimeSetup.ReadConfiguration(TestHelpers.StandardConfigFile);
            Assert.AreEqual(2, srs.LanguageSetups.Count);

            var runtime = new ScriptRuntime(srs);
            foreach (var lang in srs.LanguageSetups) {
                Assert.IsTrue((lang.Names != null) && (lang.Names.Count != 0));

                //ensure this doesn't throw
                var engine = runtime.GetEngine(lang.Names[0]);
                Assert.AreEqual(lang.DisplayName, engine.Setup.DisplayName);
            }
        }
开发者ID:Jirapong,项目名称:main,代码行数:13,代码来源:ScriptRuntimeSetupTest.cs

示例13: Scripting

        public Scripting()
        {
            Host = Python.CreateRuntime();
            Scope = Host.CreateScope();
            Engine = Host.GetEngine("Python");

            PacketHooks = new Dictionary<NSCommand, List<PacketHookCall>>();
            UpdateHooks = new List<UpdateHookCall>();
            ChatHooks = new List<ChatHookCall>();
            ChatCommandHooks = new Dictionary<string, List<ChatCommandHookCall>>();
            NameFormatHooks = new List<NameFormatHookCall>();
            PlayerXPHooks = new List<PlayerXPHookCall>();
        }
开发者ID:SandonV,项目名称:OpenSMO,代码行数:13,代码来源:Scripting.cs

示例14: GetObject

        public object GetObject(string objectName)
        {
            Dictionary<string, object> instances = new Dictionary<string, object>();

            ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
            ScriptRuntime runtime = new ScriptRuntime(setup);
            runtime.LoadAssembly(Assembly.GetExecutingAssembly());

            ScriptEngine engine = runtime.GetEngine("IronPython");
            runtime.Globals.SetVariable("instances", instances);
            engine.ExecuteFile("Objects.py", runtime.Globals);

            return instances[objectName];
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:14,代码来源:PyCrust.cs

示例15: Window_Loaded

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(AplusCore.Runtime.AplusLanguageContext.LanguageSetup);

            ScriptRuntime dlrRuntime = new ScriptRuntime(setup);
            _engine = dlrRuntime.GetEngine(@"A+");
            _ms = new MemoryStream();
            var sw = new StreamWriter(_ms);
            dlrRuntime.IO.SetErrorOutput(_ms, sw);
            dlrRuntime.IO.SetOutput(_ms, sw);

            _scope = _engine.CreateScope();
        }
开发者ID:sammoorhouse,项目名称:aplusdotnet,代码行数:14,代码来源:MainWindow.xaml.cs


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