我已经创建了将IronPython代码嵌入C#的代码。
public ScriptEngine GetEngine() {
if( _engine != null )
return _engine;
_engine = Python.CreateEngine();
var paths = _engine.GetSearchPaths();
paths.Add( _pythonPath );
_engine.SetSearchPaths( paths );
var runtime = _engine.Runtime;
runtime.LoadAssembly( typeof( CharacterCore ).Assembly );
return _engine;
}
public IAbility Movement() {
var engine = GetEngine();
var script = engine.CreateScriptSourceFromFile( Path.Combine( _pythonPath, "movement.py" ) );
var code = script.Compile();
var scope = engine.CreateScope();
code.Execute( scope );
return scope.GetVariable( "result" );
}
在同一解决方案中的单独Python项目中使用适当的Python代码。代码本身可以工作,但是如果我在Python代码中设置断点,则永远不会触发。有没有办法让调试器进入Python代码?
我正在使用Visual Studio 2015 RC(也是Visual Studio 2013),Python Tools for Visual Studio(使用IronPython Launcher进行Python代码)。我尝试过从字符串和文件创建脚本源,但调试从未正常工作。
__file__
,它会显示什么? - Pavel Minaev-X:Debug
(或者在托管时指定options["Debug"] = true
,然后创建引擎CreateEngine(options)
)。这将向托管调试器提供基本的调试信息,让你能够处理Python代码。与PTVS调试相比,它有限制,例如你会在堆栈中看到混淆的名称等,但如果你一定要同时调试这两种类型的代码,这是唯一的选择。 - Pavel Minaev