public PythonLoader(string code, string className = "PyClass") { //creating engine and stuff engine = Python.CreateEngine(); scope = engine.CreateScope(); //loading and compiling code source = engine.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements); compiled = source.Compile(); }
public void CompileCodeFromClass(string code, string className) { //loading and compiling code Source = Engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements); _compiled = Source.Compile(); //now executing this code (the code should contain a class) _compiled.Execute(Scope); //now creating an object that could be used to access the stuff inside a python script _pythonClass = Engine.Operations.Invoke(Scope.GetVariable(className)); }
public pyDissector(string fileName) { engine = Python.CreateEngine(); scope = engine.CreateScope(); var runtime = engine.Runtime; runtime.LoadAssembly(typeof(PacketDotNet.Packet).Assembly); runtime.LoadAssembly(typeof(pyDissector).Assembly); src = engine.CreateScriptSourceFromFile(fileName); program = src.Compile(); var result = program.Execute(scope); var filterString = scope.GetVariable<string>("nativeFilterString"); myFilter = filterGen.genFilter(filterString); parseFunc = scope.GetVariable<Func<Packet, HLPacket>>("parsePacket"); }
public void LoadCode(string code) { Source = Engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements); Source.Compile(); }