本文整理汇总了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!");
}
}
示例2: ExecuteTopMethod
public static void ExecuteTopMethod(string methName, ScriptScope scope)
{
Action act;
if (scope.TryGetVariable<Action>(methName, out act))
{
act.Invoke();
}
}
示例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);
}
}
示例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;
}