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


C# ScriptScope.SetVariable方法代码示例

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


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

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

示例2: LoadCoreModule

        /// <summary>
        /// Load the core module that offers access to the simulation environment.
        /// </summary>
        public void LoadCoreModule()
        {
            scope = engine.CreateScope();

            // Allow scriptable access to...
            scope.SetVariable("status", Program.form.toolStripStatus);  // Statusbar.
            scope.SetVariable("log", Program.form.txtLog); // Simulation log.
            try
            {
                e_script = engine.CreateScriptSourceFromFile("syeon.py");
                e_script.Execute(scope);
            }
            catch(Exception e)
            {
                DialogResult ans = MessageBox.Show(
                e.Message, SSE, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                if(ans == DialogResult.Abort)
                {
                    Program.form.Close();
                }
                else if(ans == DialogResult.Retry)
                {
                    LoadCoreModule(); // Recursion rules!
                }
            }
        }
开发者ID:stpettersens,项目名称:Syeon,代码行数:29,代码来源:ScriptingEngine.cs

示例3: Load

        public override void Load(string code = "")
        {
            Engine = IronPython.Hosting.Python.CreateEngine();
            Scope = Engine.CreateScope();
            Scope.SetVariable("Commands", chatCommands);
            Scope.SetVariable("DataStore", DataStore.GetInstance());
            Scope.SetVariable("Find", Find.GetInstance());
            Scope.SetVariable("GlobalData", GlobalData);
            Scope.SetVariable("Plugin", this);
            Scope.SetVariable("Server", Pluton.Server.GetInstance());
            Scope.SetVariable("ServerConsoleCommands", consoleCommands);
            Scope.SetVariable("Util", Util.GetInstance());
            Scope.SetVariable("Web", Web.GetInstance());
            Scope.SetVariable("World", World.GetInstance());
            try {
                Engine.Execute(code, Scope);
                Class = Engine.Operations.Invoke(Scope.GetVariable(Name));
                Globals = Engine.Operations.GetMemberNames(Class);

                object author = GetGlobalObject("__author__");
                object about = GetGlobalObject("__about__");
                object version = GetGlobalObject("__version__");
                Author = author == null ? "" : author.ToString();
                About = about == null ? "" : about.ToString();
                Version = version == null ? "" : version.ToString();

                State = PluginState.Loaded;
            } catch (Exception ex) {
                Logger.LogException(ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
开发者ID:Notulp,项目名称:Pluton,代码行数:34,代码来源:PYPlugin.cs

示例4: Initialize

 public void Initialize()
 {
     _pyEngine = Python.CreateEngine();
     _pyScope = _pyEngine.CreateScope();
     _pyScope.SetVariable("handler", _scriptHandler); // ([name], [value]) 
     _pyScope.SetVariable("game", MainWindow.Game);
     _pyScope.SetVariable("config", MainWindow.Config);
 }
开发者ID:mrommel,项目名称:MiRo.SimHexWorld,代码行数:8,代码来源:PythonEngine.cs

示例5: ThisAddIn_Startup

 private void ThisAddIn_Startup(object sender, System.EventArgs e)
 {
     _python = Python.CreateEngine();
     _python_scope = _python.CreateScope();
     _python_scope.SetVariable("Application", Application);
     _python_scope.SetVariable("Function", Application.WorksheetFunction);
     _python_scope.SetVariable("Cells", Application.Cells);
 }
开发者ID:mimura1133,项目名称:mm_Python_for_Excel,代码行数:8,代码来源:ThisAddIn.cs

示例6: Init

 public void Init(string player)
 {
     m_scope = m_engine.CreateScope();
     m_scope.SetVariable("player", player);
     m_scope.SetVariable("ClearBox", BoxState.Clear);
     m_scope.SetVariable("XBox", BoxState.X);
     m_scope.SetVariable("OBox", BoxState.O);
     source = m_engine.CreateScriptSourceFromString(System.IO.File.ReadAllText("AI.py"), SourceCodeKind.AutoDetect);
 }
开发者ID:ethiele,项目名称:TickTackToe,代码行数:9,代码来源:AI.cs

示例7: Core

 public Core()
 {
     _engine = Python.CreateEngine();
     _scope = _engine.CreateScope();
     _scope.SetVariable("printChat", new Action<string>(Chat.Print));
     _scope.SetVariable("PlayerInstance", Player.Instance);
     _scope.SetVariable("drawCircle", new Action<string, float, AIHeroClient>(pyDrawCircle));
     Game.OnTick += Game_OnTick;
     Drawing.OnDraw += Drawing_OnDraw;
 }
开发者ID:newchild,项目名称:EloBuddy-Addons,代码行数:10,代码来源:Core.cs

示例8: MDbgScriptForm

        public MDbgScriptForm(SptWrapper ext)
        {
            _host = Ruby.CreateEngine();

            _scope = _host.CreateScope();
            _scope.SetVariable("ext", ext);
            _scope.SetVariable("dbg", new Environment(this));

            _ext = ext;
            InitializeComponent();
        }
开发者ID:killbug2004,项目名称:SDbgExt2,代码行数:11,代码来源:MDbgScriptForm.cs

示例9: Engine

 public Engine(string filePath,Inventor.PlanarSketch oSketch,Inventor.Application oApp, double slotHeight, double slotWidth)
 {
     _engine = Python.CreateEngine(new Dictionary<string, object>() { {"Frames", true}, {"FullFrames", true}});
     _runtime = _engine.Runtime;
     Assembly invAssembly = Assembly.LoadFile(@"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_17.0.0.0__d84147f8b4276564\Autodesk.Inventor.interop.dll");
     _runtime.LoadAssembly(invAssembly);
     _scope = _engine.CreateScope();
     //Make variable names visible within the python file.  These string names will be used an arguments in the python file.
     _scope.SetVariable("oPlanarSketch",oSketch);
     _scope.SetVariable("oApp",oApp);
     _scope.SetVariable("slotHeight",slotHeight);
     _scope.SetVariable("slotWidth",slotWidth);
     ScriptSource _script = _engine.CreateScriptSourceFromFile(filePath);
     _code = _script.Compile();
 }
开发者ID:frankfralick,项目名称:InventorAddIns,代码行数:15,代码来源:Engine.cs

示例10: ReplWindow

        public ReplWindow()
        {
            InitializeComponent();

            _engine = Ruby.CreateEngine();
            _scope = Ruby.CreateRuntime().CreateScope();

            _scope.SetVariable("pi", Math.PI);
            _scope.SetVariable("e", Math.E);
            _scope.SetVariable("_", new Extension());

            var source = _engine.CreateScriptSourceFromString("require 'RubyInt.exe'\nrequire 'Mathos.dll'\nrequire '" + Settings.DataDirectory + "Std.rb'", SourceCodeKind.Statements);

            source.Execute(_scope);
        }
开发者ID:rodriada000,项目名称:Mathos-Project,代码行数:15,代码来源:ReplWindow.xaml.cs

示例11: EvaluateContext

 private static void EvaluateContext(ScriptScope scope, ICompiledCodeContext context)
 {
     scope.SetVariable("contexts", context);
     scope.SetVariable("hosts", context.Hosts);
     scope.SetVariable("groups", context.Groups);
     scope.SetVariable("sites", context.Sites);
     scope.SetVariable("equipments", context.Equipments);
     scope.SetVariable("signals", context.Signals);
     scope.SetVariable("affairs", context.Affairs);
     scope.SetVariable("commands", context.Commands);
     scope.SetVariable("users", context.Users);
 }
开发者ID:dalinhuang,项目名称:tdcodes,代码行数:12,代码来源:EngineUtility.cs

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

示例13: Plugin

 public Plugin(string filename)
 {
     this.filename = filename;
     scope = engine.CreateScope();
     scope.SetVariable("hookme", Program.data.pluginMngr.pluginsApi);
     engine.SetSearchPaths(Program.data.configuration.lstPluginsSearchPath);
 }
开发者ID:CaineQT,项目名称:hookme,代码行数:7,代码来源:Plugin.cs

示例14: RenderView

        private void RenderView(ScriptScope scope, ViewContext context, TextWriter writer)
        {
            scope.SetVariable("view_data", context.ViewData);
            scope.SetVariable("model", context.ViewData.Model);
            scope.SetVariable("context", context);
            scope.SetVariable("response", context.HttpContext.Response);
            scope.SetVariable("url", new RubyUrlHelper(context.RequestContext));
            scope.SetVariable("html", new RubyHtmlHelper(context, new Container(context.ViewData)));
            scope.SetVariable("ajax", new RubyAjaxHelper(context, new Container(context.ViewData)));

            var script = new StringBuilder();
            Template.ToScript("render_page", script);

            if (_master != null)
                _master.Template.ToScript("render_layout", script);
            else
                script.AppendLine("def render_layout; yield; end");

            script.AppendLine("def view_data.method_missing(methodname); get_Item(methodname.to_s); end");
            script.AppendLine("render_layout { |content| render_page }");

            try
            {
                _rubyEngine.ExecuteScript(script.ToString(), scope);
            }
            catch (Exception e)
            {
                writer.Write(e.ToString());
            }
        }
开发者ID:jdhardy,项目名称:ironrubymvc,代码行数:30,代码来源:RubyView.cs

示例15: Py

 public Py(Bot bot)
 {
     this.bot = bot;
     engine = Python.CreateEngine();
     scope = engine.CreateScope();
     scope.SetVariable("tools", new PythonTools());
     var outputStream = new ProducerConsumerStream();
     var outputStreamWriter = new StreamWriter(outputStream);
     outputStreamReader = new StreamReader(outputStream);
     engine.Runtime.IO.SetOutput(outputStream, outputStreamWriter);
 }
开发者ID:Baggykiin,项目名称:BaggyBot-2,代码行数:11,代码来源:Py.cs


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