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


C# ScriptEngine.CreateScope方法代码示例

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


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

示例1: IPRunner

        public IPRunner(World world, GameEngine engine, Player player)
        {
            m_player = player;
            m_scriptOutputStream = new MyStream(player.Send);

            m_scriptEngine = IronPython.Hosting.Python.CreateEngine();

            InitRuntime(m_scriptEngine.Runtime);

            m_exprScope = m_scriptEngine.CreateScope();
            InitScope(m_exprScope, world, engine, player);

            m_scriptScope = m_scriptEngine.CreateScope();
            InitScope(m_scriptScope, world, engine, player);
        }
开发者ID:Fulborg,项目名称:dwarrowdelf,代码行数:15,代码来源:IPRunner.cs

示例2: IronPythonCompletionProvider

        /// <summary>
        /// Class constructor
        /// </summary>
        public IronPythonCompletionProvider()
        {
            _engine = Python.CreateEngine();
            _scope = _engine.CreateScope();

            VariableTypes = new Dictionary<string, Type>();
            ImportedTypes = new Dictionary<string, Type>();

            RegexToType.Add(singleQuoteStringRegex, typeof(string));
            RegexToType.Add(doubleQuoteStringRegex, typeof(string));
            RegexToType.Add(doubleRegex, typeof(double));
            RegexToType.Add(intRegex, typeof(int));
            RegexToType.Add(arrayRegex, typeof(List));
            RegexToType.Add(dictRegex, typeof(PythonDictionary));

            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            if (assemblies.Any(x => x.FullName.Contains("RevitAPI")) && assemblies.Any(x => x.FullName.Contains("RevitAPIUI")))
            {
                try
                {
                    _scope.Engine.CreateScriptSourceFromString("import clr\n", SourceCodeKind.Statements).Execute(_scope);

                    var revitImports =
                        "clr.AddReference('RevitAPI')\nclr.AddReference('RevitAPIUI')\nfrom Autodesk.Revit.DB import *\nimport Autodesk\n";

                    _scope.Engine.CreateScriptSourceFromString(revitImports, SourceCodeKind.Statements).Execute(_scope);
                }
                catch
                {
                    DynamoLogger.Instance.Log("Failed to load Revit types for autocomplete.  Python autocomplete will not see Autodesk namespace types.");
                }
            }

            if (!assemblies.Any(x => x.FullName.Contains("LibGNet")))
            {
                AssemblyHelper.LoadLibG();

                //refresh the assemblies collection
                assemblies = AppDomain.CurrentDomain.GetAssemblies();
            }

            if (assemblies.Any(x => x.FullName.Contains("LibGNet")))
            {
                try
                {
                    _scope.Engine.CreateScriptSourceFromString("import clr\n", SourceCodeKind.Statements).Execute(_scope);

                    var libGImports =
                        "import clr\nclr.AddReference('LibGNet')\nfrom Autodesk.LibG import *\n";

                    _scope.Engine.CreateScriptSourceFromString(libGImports, SourceCodeKind.Statements).Execute(_scope);
                }
                catch (Exception e)
                {
                    DynamoLogger.Instance.Log(e.ToString());
                    DynamoLogger.Instance.Log("Failed to load LibG types for autocomplete.  Python autocomplete will not see Autodesk namespace types.");
                }
            }
        }
开发者ID:riteshchandawar,项目名称:Dynamo,代码行数:63,代码来源:IronPythonCompletionProvider.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: Main

        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args">Command line args.</param>
        public static void Main(string[] args)
        {
            engine = Python.CreateEngine();
            scope = engine.CreateScope();

            engine.Runtime.LoadAssembly(typeof(TurntableBot).Assembly);
            engine.Runtime.LoadAssembly(typeof(JObject).Assembly);
            engine.Runtime.IO.RedirectToConsole();

            ScriptSource source = null;

            if (File.Exists(Script))
            {
                source = engine.CreateScriptSourceFromFile(Script);
            }
            else
            {
                Console.WriteLine("File not found");
            }

            if (source != null)
            {
                try
                {
                    source.Execute(scope);
                }
                catch (Exception e)
                {
                    ExceptionOperations ops = engine.GetService<ExceptionOperations>();
                    Console.WriteLine(ops.FormatException(e));
                }
            }

            Console.ReadLine();
        }
开发者ID:nmalaguti,项目名称:Turntable-API-sharp,代码行数:39,代码来源:Program.cs

示例5: CreateRuntime

 /// <summary>
 /// Creates instances of the Ruby engine and Ruby scope
 /// </summary>
 public static void CreateRuntime()
 {
     _rubyRuntime = IronRuby.Ruby.CreateRuntime();
       _rubyEngine = IronRuby.Ruby.GetEngine(_rubyRuntime);
       _rubyScope = _rubyEngine.CreateScope();
       _rubyEngine.Execute(@"load_assembly 'IronRuby.Libraries', 'IronRuby.StandardLibrary.Zlib'", _rubyScope);
 }
开发者ID:revam,项目名称:Gemini,代码行数:10,代码来源:Ruby.cs

示例6: Create

        public ICondition Create()
        {
            _engine = Ruby.CreateEngine();

            string rubyRuleTemplate;
            using (var stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream(_dslFileName))
            {
                using (var reader = new StreamReader(stream))
                {
                    rubyRuleTemplate = reader.ReadToEnd();
                }
            }
            rubyRuleTemplate = rubyRuleTemplate.Replace("$ruleAssembly$", _contextType.Namespace.Replace(".", "::"));
            rubyRuleTemplate = rubyRuleTemplate.Replace("$contextType$", _contextType.Name);
            rubyRuleTemplate = rubyRuleTemplate.Replace("$condition$", _condition);
            _source = _engine.CreateScriptSourceFromString(rubyRuleTemplate);

            var scope = _engine.CreateScope();
            _assemblies.ForEach(a => _engine.Runtime.LoadAssembly(a));

            _engine.Execute(_source.GetCode(), scope);
            var @class = _engine.Runtime.Globals.GetVariable("RubyRuleFactory");

            var installer = _engine.Operations.CreateInstance(@class);
            var rule = installer.Create();

            return (ICondition)rule;
        }
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:28,代码来源:RubyEngine.cs

示例7: RubyInstaller

        public RubyInstaller(string fileName, List<Assembly> assemblies)
        {
            this.fileName = fileName;
            assemblies.AddRange(new[] { typeof(IServiceLocator).Assembly, typeof(IConvention).Assembly });

            if(engine == null)
            {
               lock(@lock)
               {
                   if(engine == null)
                   {
                       engine = IronRuby.Ruby.CreateEngine();
                       scope = engine.CreateScope();

                       assemblies.ForEach(a => engine.Runtime.LoadAssembly(a));
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.Installer.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.SiegeDSL.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RubyRegistration.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.RegistrationHandlerFactory.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.DefaultRegistrationHandler.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.DefaultInstanceRegistrationHandler.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.ConditionalRegistrationHandler.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.ConditionalInstanceRegistrationHandler.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.NamedRegistrationHandler.rb");
                       LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.NamedInstanceRegistrationHandler.rb");
                   }
               }
            }

            this.source = engine.CreateScriptSourceFromFile(this.fileName);
        }
开发者ID:chandanchopra,项目名称:Siege,代码行数:31,代码来源:RubyInstaller.cs

示例8: PythonScriptReader

        public PythonScriptReader()
        {
            _engine = Python.CreateEngine();
            _escope = _engine.CreateScope();

            var reader = new StreamReader(new FileStream(@"Scripts\Script.py", FileMode.Open, FileAccess.Read));
            string scriptText = reader.ReadToEnd();
            reader.Close();

            _engine.Execute(scriptText, _escope);

            if (!_escope.TryGetVariable("GeneratorFunc", out _randomGenerator))
            {
                MessageBox.Show("Error Occurred in Executing python script! - GeneratorFunc", "Error");
                throw new Exception("Error Occurred in Executing python script!");
            }
            if (!_escope.TryGetVariable("userDefinedFunc", out _userDefinedMethod))
            {
                MessageBox.Show("Error Occurred in Executing python script! - userDefinedFunc", "Error");
                throw new Exception("Error Occurred in Executing python script!");
            }
            if (!_escope.TryGetVariable("LifeSpanMapper", out _lifeTimeMapper))
            {
                MessageBox.Show("Error Occurred in Executing python script! - LifeSpanMapper", "Error");
                throw new Exception("Error Occurred in Executing python script!");
            }
            if (!_escope.TryGetVariable("DelayMapper", out _delayTimeMapper))
            {
                MessageBox.Show("Error Occurred in Executing python script! - DelayMapper", "Error");
                throw new Exception("Error Occurred in Executing python script!");
            }
        }
开发者ID:taesiri,项目名称:Simulation,代码行数:32,代码来源:PythonScriptReader.cs

示例9: IronPythonCompletionProvider

        /// <summary>
        /// Class constructor
        /// </summary>
        public IronPythonCompletionProvider()
        {
            _engine = Python.CreateEngine();
            _scope = _engine.CreateScope();

            VariableTypes = new Dictionary<string, Type>();
            ImportedTypes = new Dictionary<string, Type>();

            RegexToType.Add(singleQuoteStringRegex, typeof(string));
            RegexToType.Add(doubleQuoteStringRegex, typeof(string));
            RegexToType.Add(doubleRegex, typeof(double));
            RegexToType.Add(intRegex, typeof(int));
            RegexToType.Add(arrayRegex, typeof(List));
            RegexToType.Add(dictRegex, typeof(PythonDictionary));

            try
            {
                _scope.Engine.CreateScriptSourceFromString("import clr\n", SourceCodeKind.Statements).Execute(_scope);

                var revitImports =
                    "clr.AddReference('RevitAPI')\nclr.AddReference('RevitAPIUI')\nfrom Autodesk.Revit.DB import *\nimport Autodesk\n";

                _scope.Engine.CreateScriptSourceFromString(revitImports, SourceCodeKind.Statements).Execute(_scope);
            }
            catch
            {
                DynamoLogger.Instance.Log("Failed to load Revit types for autocomplete.  Python autocomplete will not see Autodesk namespace types.");
            }
        }
开发者ID:epeter61,项目名称:Dynamo,代码行数:32,代码来源:IronPythonCompletionProvider.cs

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

示例11: InitialzeInterpreter

        /// <summary>
        /// 初始化解释器
        /// </summary>
        public void InitialzeInterpreter()
        {
            pythonEngine = Python.CreateEngine();
            pythonScope = pythonEngine.CreateScope();

            string initialString =
            @"
            import clr, sys
            import System.Collections.Generic.List as List
            clr.AddReference('Clover')
            from Clover import *
            # 获取CloverController的实例
            clover = CloverController.GetInstance();
            # 取出所有的函数指针
            FindFacesByVertex = clover.FindFacesByVertex
            GetVertex = clover.GetVertex
            CutFaces = clover.AnimatedCutFaces
            _CutFaces = clover.CutFaces
            _RotateFaces = clover.RotateFaces
            RotateFaces = clover.AnimatedRotateFaces
            Undo = clover.Undo
            Redo = clover.Redo
            ";

            pythonEngine.Execute(initialString, pythonScope);
        }
开发者ID:cedricporter,项目名称:Clover,代码行数:29,代码来源:CloverInterpreter.cs

示例12: PythonTF

 public PythonTF()
 {
     engine = Python.CreateEngine();
     scope = engine.CreateScope();
     Script = "value";
     ScriptWorkMode = ScriptWorkMode.不进行转换;
 }
开发者ID:CHERRISHGRY,项目名称:Hawk,代码行数:7,代码来源:PythonTF.cs

示例13: Main

        private static void Main()
        {
            try
            {
                PyEngine = Python.CreateEngine();
                NtrClient = new NtrClient();
                ScriptHelper = new ScriptHelper();

                GlobalScope = PyEngine.CreateScope();
                GlobalScope.SetVariable("nc", ScriptHelper);

                LoadConfig();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                GCmdWindow = new CmdWindow();
                Dc = new DebugConsole();
                Application.Run(GCmdWindow);
            }
            catch (Exception e)
            {
                BugReporter br = new BugReporter(e, "Program exception");
                MessageBox.Show(
                    @"WARNING - NTRDebugger has encountered an error" + Environment.NewLine +
                    @"This error is about to crash the program, please send the generated" + Environment.NewLine +
                    @"Error log to imthe666st!" + Environment.NewLine + Environment.NewLine +
                    @"Sorry for the inconvinience -imthe666st"
                    );
            }
        }
开发者ID:imthe666st,项目名称:NTRClient,代码行数:30,代码来源:Program.cs

示例14: Engine

        public Engine()
        {
            var options = new Dictionary<string, object>();
            options["DivisionOptions"] = PythonDivisionOptions.New;
            _history = new NullStream();
            _output = new EventRaisingStreamWriter(_history);
            _output.StringWritten += _output_StringWritten;
            _engine = Python.CreateEngine(options);
            _engine.Runtime.IO.SetOutput(_history, _output);
            _engine.Runtime.IO.SetErrorOutput(_history, _output);
            _scope = _engine.CreateScope();
            foreach (var t in _pluggable)
            {
                _scope.SetVariable(t.Name, DynamicHelpers.GetPythonTypeFromType(t));
            }
            _scope.SetVariable("CalculatorFunctions", DynamicHelpers.GetPythonTypeFromType(typeof(CalculatorFunctions)));
            _functioncache = new Dictionary<string, string>();
            //hidden functions
            _functioncache.Add("Var", "CalculatorFunctions.Var");
            _functioncache.Add("FncList", "CalculatorFunctions.FncList");
            _functioncache.Add("RegFunction", "CalculatorFunctions.RegFunction");

            foreach (var f in _functions)
            {
                if (_functioncache.ContainsKey(f.Name)) continue;
                _functioncache.Add(f.Name, f.FullName);
            }
            LoadBitops();
        }
开发者ID:webmaster442,项目名称:ECalc,代码行数:29,代码来源:IronPythonEngine.cs

示例15: ScriptHost

        public ScriptHost()
        {
            m_engine = Python.CreateEngine();
            m_scope = m_engine.CreateScope();

            CreateOutputBuffer();
        }
开发者ID:BoykoDmitry,项目名称:csharp,代码行数:7,代码来源:ScriptHost.cs


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