我正在嘗試將[rlcompleter][1]
功能添加到IronTextBoxControl2的中。如何在託管IronPython 2.0時發佈模塊「__main__」?
不過,我有一個很難麻煩線路:
import __main__
在
rlcompleter.py
。這是因爲我沒有這樣的模塊。我一直在搜索/篩選IronPython 2.0代碼庫,試圖找出如何發佈模塊。
看來我可以從IronPython.Runtime.PythonContext
的實例與PublishModule(string name, PythonModule module)
的方法這樣做。但我遇到了下列麻煩:
- 獲得
PythonContext
實例 - 獲得
PythonModule
實例
我有,是ScriptEngine
和ScriptScope
。我希望範圍將作爲模塊__main__
發佈。據我所知,範圍已經附加到模塊,但我不知道如何訪問它。
這裏是代碼的時候,我想這綁在一起:
/// <summary>
/// Set up an IronPython environment - for interactive shell or for canned scripts
/// </summary>
public void SetupEnvironment(ScriptEngine engine, ScriptScope scope)
{
// add variables from Revit
scope.SetVariable("__revit__", _commandData.Application);
scope.SetVariable("__commandData__", _commandData);
scope.SetVariable("__message__", _message);
scope.SetVariable("__elements__", _elements);
scope.SetVariable("__result__", (int)Result.Succeeded);
// add preconfigures variables
scope.SetVariable("__vars__", RevitPythonShellApplication.GetVariables());
/* register scope as __main__ module here?! */
// add the search paths
AddSearchPaths(engine);
}