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


C# ScriptRuntime.CreateScope方法代码示例

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


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

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

示例2: register

        public void register()
        {
            engine = Python.CreateEngine();
            scope = null;
            runtime = engine.Runtime;

            scope = runtime.CreateScope();
        }
开发者ID:sajithdil,项目名称:Cutting_Edge_Program,代码行数:8,代码来源:PythonObject.cs

示例3: IronPythonScriptEngine

        public IronPythonScriptEngine()
        {
            runtime = engine.Runtime;
            runtime.LoadAssembly(Assembly.GetAssembly(typeof(Mogre.Vector3)));
            scope = runtime.CreateScope();

            // install built-in scripts
            install(new Script(builtin));
        }
开发者ID:agustinsantos,项目名称:mogregis3d,代码行数:9,代码来源:IronPythonScriptEngine.cs

示例4: RunProgram

        public void RunProgram()
        {
            engine = Python.CreateEngine();
            runtime = engine.Runtime;
            scope = runtime.CreateScope();

            RunExpression();

            RunInScope();

            RunFromFile();
        }
开发者ID:GrahamClark,项目名称:TestConsoleApp,代码行数:12,代码来源:Runner.cs

示例5: ValidateGetItems

        private void ValidateGetItems(ScriptRuntime runtime) {
            ScriptScope scope = runtime.CreateScope();

            var dict = new KeyValuePair<string, object>("var1", 1);
            scope.SetVariable(dict.Key, dict.Value);

            TestHelpers.AreEqualCollections<KeyValuePair<string, object>>(new[] { dict }, scope.GetItems());

            var newDict = new KeyValuePair<string, object>("newVar", "newval");
            scope.SetVariable(newDict.Key, newDict.Value);

            TestHelpers.AreEqualCollections<KeyValuePair<string, object>>(new[] { dict, newDict }, scope.GetItems());
        }
开发者ID:Jirapong,项目名称:main,代码行数:13,代码来源:ScriptScopeTestHelper.cs

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

示例7: AnalysisModule

        public AnalysisModule()
        {
            var t = Directory.GetCurrentDirectory();
            SourcePath = t + "\\Analysis";
            if (!Directory.Exists(SourcePath))
            {
                Directory.CreateDirectory(SourcePath);
            }

            ASRT = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(t+"\\NSCore.dll.config"));
            ASRT.LoadAssembly(Assembly.GetAssembly(typeof(IDevice)));
            ASRT.LoadAssembly(Assembly.GetAssembly(typeof(Marshal)));

            Scope = ASRT.CreateScope();
        }
开发者ID:babaq,项目名称:NeuSys,代码行数:15,代码来源:AnalysisModule.cs

示例8: RubyEngine

        public RubyEngine(object appScope)
        {
            var runtimeSetup = new ScriptRuntimeSetup();
            runtimeSetup
                .LanguageSetups
                .Add(new LanguageSetup("IronRuby.Runtime.RubyContext, IronRuby",
                                       "IronRuby 1.0",
                                       new[] { "IronRuby", "Ruby", "rb" },
                                       new[] { ".rb" }));

            runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, runtimeSetup);

            scope = runtime.CreateScope();
            scope.SetVariable("app", appScope);

            engine = runtime.GetEngine("IronRuby");
        }
开发者ID:vquaiato,项目名称:TDC2010-IronRuby-samples,代码行数:17,代码来源:RubyEngine.cs

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

示例10: Main

        static void Main(string[] args)
        {
            var runtimeSetup = Python.CreateRuntimeSetup(new Dictionary<string, object>());
            runtimeSetup.DebugMode = true;

            var runtime = new ScriptRuntime(runtimeSetup);

            var scope = runtime.CreateScope(new Dictionary<string, object> {
                { "name" , "Batman" }
            });

            var engine = runtime.GetEngine("py");
            var scriptSource = engine.CreateScriptSourceFromFile("script.py");
            var compiledCode = scriptSource.Compile();

            compiledCode.Execute(scope);
        }
开发者ID:k0st1x,项目名称:DLR-Usage-Sample,代码行数:17,代码来源:Program.cs

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

示例12: eval

        protected bool eval(string script, object propertyValue)
        {
            ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
            ScriptRuntime runtime = new ScriptRuntime(setup);

            ScriptScope scope = runtime.CreateScope("IronPython");
            scope.SetVariable("property_value", propertyValue);
            scope.SetVariable("result", true);

            scope.Engine.CreateScriptSourceFromString("import clr", SourceCodeKind.SingleStatement).Execute(scope);
            scope.Engine.CreateScriptSourceFromString("clr.AddReference('System')", SourceCodeKind.SingleStatement).Execute(scope);
            scope.Engine.CreateScriptSourceFromString("from System import *", SourceCodeKind.SingleStatement).Execute(scope);
            ScriptSource source = scope.Engine.CreateScriptSourceFromString(script, SourceCodeKind.Statements);
            source.Execute(scope);

            bool result = (bool)scope.GetVariable("result");

            return result;
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:19,代码来源:ValidationBase.cs

示例13: ConstructObject

        protected object ConstructObject(ContainedObject co)
        {
            if (_staticObjects.ContainsKey(co.Name)) {
                return _staticObjects[co.Name];
            } else {

                //in the full CodeVoyeur version, this is cached!
                ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
                ScriptRuntime runtime = new ScriptRuntime(setup);
                runtime.LoadAssembly(Assembly.GetExecutingAssembly());

                ScriptScope scope = runtime.CreateScope("IronPython");
                ScriptSource source = scope.Engine.CreateScriptSourceFromString("from HostedIronPython.Model import *", SourceCodeKind.SingleStatement);
                source.Execute(scope);

                scope.SetVariable("instance", new object());

                scope.SetVariable("reference", new Func<string, object>
                    (
                        delegate(string refName) {
                            if (_staticObjects.ContainsKey(refName))
                                return _staticObjects[refName];
                            else
                                return GetFilling(refName);
                        }
                    ));

                ScriptSource configSource = scope.Engine.CreateScriptSourceFromString(co.Script, SourceCodeKind.Statements);
                configSource.Execute(scope);

                if (co.IsStatic)
                    return _staticObjects[co.Name] = scope.GetVariable("instance");
                else
                    return scope.GetVariable("instance");
            }
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:36,代码来源:PyCrust.cs

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

示例15: getQuery

        private Func<Album, bool> getQuery(string queryName, string searchParam)
        {
            XDocument doc = XDocument.Load("AlbumQueries.xml");

            var query = (from q in doc.Descendants("query")
                           where q.Attribute("name").Value == queryName
                           select new {
                              Query = q.Value
                          }).FirstOrDefault();

            ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
            ScriptRuntime runtime = new ScriptRuntime(setup);

            ScriptScope scope = runtime.CreateScope("IronPython");
            scope.SetVariable("search_param", searchParam);

            scope.Engine.CreateScriptSourceFromString("import clr", SourceCodeKind.SingleStatement).Execute(scope);
            scope.Engine.CreateScriptSourceFromString("clr.AddReference('System')", SourceCodeKind.SingleStatement).Execute(scope);
            scope.Engine.CreateScriptSourceFromString("from System import *", SourceCodeKind.SingleStatement).Execute(scope);
            ScriptSource source = scope.Engine.CreateScriptSourceFromString(query.Query, SourceCodeKind.Statements);
            source.Execute(scope);

            return scope.GetVariable<Func<Album, bool>>("query");
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:24,代码来源:AlbumLister.cs


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