public Script(bool redirectOutput = false)
{
Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
if (engine != null)
engine.Runtime.Shutdown();
engine = Python.CreateEngine(options);
var paths = engine.GetSearchPaths();
paths.Add(Settings.GetRunningDirectory() + "Lib.zip");
engine.SetSearchPaths(paths);
scope = engine.CreateScope();
var all = System.Reflection.Assembly.GetExecutingAssembly();
engine.Runtime.LoadAssembly(all);
scope.SetVariable("MAV", MainV2.comPort);
scope.SetVariable("cs", MainV2.comPort.MAV.cs);
scope.SetVariable("Script", this);
scope.SetVariable("mavutil", this);
scope.SetVariable("Joystick", MainV2.joystick);
engine.CreateScriptSourceFromString("print 'hello world from python'").Execute(scope);
engine.CreateScriptSourceFromString("print cs.roll").Execute(scope);
if (redirectOutput)
{
//Redirect output through this writer
//this writer will not actually write to the memorystreams
OutputWriter = new Utilities.StringRedirectWriter();
engine.Runtime.IO.SetErrorOutput(new MemoryStream(), OutputWriter);
engine.Runtime.IO.SetOutput(new MemoryStream(), OutputWriter);
}
else
OutputWriter = null;
/*
object thisBoxed = MainV2.comPort.MAV.cs;
Type test = thisBoxed.GetType();
foreach (var field in test.GetProperties())
{
// field.Name has the field's name.
object fieldValue;
try
{
fieldValue = field.GetValue(thisBoxed, null); // Get value
}
catch { continue; }
// Get the TypeCode enumeration. Multiple types get mapped to a common typecode.
TypeCode typeCode = Type.GetTypeCode(fieldValue.GetType());
items.Add(field.Name);
}
*/
}