Note that there are some explanatory texts on larger screens.

plurals
  1. PODebugging IronPython scripts in hosted (embedded) environment
    text
    copied!<p>I'm writing a C# application which has IronPython (2.0.1) embedded in it. The idea is to expose portions of the application to the IronPython scripts, which the users write. </p> <p>I want to provide the ability to the users to be able to debug the scripts written by them, using the Visual Studio Debugger. Note that the scripts are run in the hosted environment and not through the IronPython executable (ipy.exe).</p> <p>After a bit of Reflector magic on the IronPython assemblies, I came up with something which lets me do that, but I'm not sure if this is the prescribed way. Basically what I do is create a "ScriptRuntime" object with the "DebugMode" property set to true and then create a python based "ScriptEngine" from the "ScriptRuntime", which I use for hosting. Code below.</p> <pre><code> ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); setup.DebugMode = true; setup.LanguageSetups.Add(Python.CreateLanguageSetup(null)); ScriptRuntime runtime = new ScriptRuntime(setup); ScriptEngine engine = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName); </code></pre> <p>Now when I execute the scripts in the hosted environment, using:</p> <pre><code> ScriptSource script = engine.CreateScriptSourceFromFile(path); CompiledCode code = script.Compile(); ScriptScope scope = engine.CreateScope(); script.Execute(scope); </code></pre> <p>I can place breakpoints in the script files and they get hit, when the script is executed.</p> <p>So, is there a better/easier way to do this?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload