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


C# ScriptScope.TryGetVariable方法代码示例

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


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

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

示例2: ExecuteTopMethod

 public static void ExecuteTopMethod(string methName, ScriptScope scope)
 {
     Action act;
       if (scope.TryGetVariable<Action>(methName, out act))
       {
     act.Invoke();
       }
 }
开发者ID:trietptm,项目名称:retoolkit,代码行数:8,代码来源:ScriptHelper.cs

示例3: SetModuleCallbacks

        /// <summary>
        /// Gets the functions in the python file and assigns the appropriate
        /// callback to them.
        /// </summary>
        /// <param name="module">The module to assign the callbacks</param>
        /// <param name="scope">The program scope</param>
        private void SetModuleCallbacks(ScriptScope scope)
        {
            Action start;
            Action<SteamFriends.ChatMsgCallback, string[]> onChatMessage;
            Action<SteamFriends.FriendMsgCallback, string[]> onFriendMessage;
            Action<SteamFriends.ChatEnterCallback> onSelfEnterChat;
            Action<SteamFriends.PersonaStateCallback> onEnterChat;
            Action<SteamFriends.ChatMemberInfoCallback> onLeaveChat;

            try
            {
                if (scope.TryGetVariable("Start", out start))
                {
                    Start = start;
                }

                if (scope.TryGetVariable("OnChatMessage", out onChatMessage))
                {
                    ChatMessage = onChatMessage;
                }

                if (scope.TryGetVariable("OnFriendMessage", out onFriendMessage))
                {
                    FriendMessage = onFriendMessage;
                }

                if (scope.TryGetVariable("OnSelfChatEnter", out onSelfEnterChat))
                {
                    SelfChatEnterCallback = onSelfEnterChat;
                }

                if (scope.TryGetVariable("OnChatEnter", out onEnterChat))
                {
                    ChatEnterCallback = onEnterChat;
                }

                if (scope.TryGetVariable("OnChatLeave", out onLeaveChat))
                {
                    ChatLeaveCallback = onLeaveChat;
                }
            }
            catch (Exception e)
            {
                ModuleManager.PrintStackFrame(e);
            }
        }
开发者ID:bakerj76,项目名称:SteamNerd,代码行数:52,代码来源:Module.cs

示例4: SetScope

        public string SetScope(ScriptScope scope)
        {
            _currentScope = scope;
            string scopeName;

            if (scope.TryGetVariable<string>("__name__", out scopeName)) {
                _currentScopeName = scopeName;
            } else {
                _currentScopeName = String.Empty;
            }

            var curScopeChanged = CurrentScopeChanged;
            if (curScopeChanged != null) {
                curScopeChanged(this, EventArgs.Empty);
            }

            return _currentScopeName;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:18,代码来源:RemotePythonEvaluator.cs


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