我正在尝试将[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);
}