public void ResetEngine(bool debugmode = false) { if (_python != null) { _python.Runtime.Shutdown(); } ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); setup.DebugMode = debugmode; setup.LanguageSetups.Add(Python.CreateLanguageSetup(null)); ScriptRuntime runtime = new ScriptRuntime(setup); _python = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName); LoadAssembly(typeof(Prefab.Bitmap).Assembly); LoadAssembly(typeof(PrefabUtils.PathDescriptor).Assembly); if (_consoleOutput == null) { _consoleOutput = new MemoryStream(); } _python.Runtime.IO.SetOutput(_consoleOutput, Encoding.Default); // _python.Runtime.GetClrModule().GetVariable("AddReference")("Prefab"); //_python = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName); //Instance = new PythonScriptHost(false); }
private ScriptEngine CreateEngine() { var setup = new ScriptRuntimeSetup(); setup.LanguageSetups.Add(Python.CreateLanguageSetup(null)); setup.DebugMode = true; var runtime = new ScriptRuntime(setup); return(runtime.GetEngine("py")); }
public void RunPythonCode() { var setup = new ScriptRuntimeSetup(); setup.LanguageSetups.Add(Python.CreateLanguageSetup(null)); var runtime = new ScriptRuntime(setup); runtime.IO.RedirectToConsole(); ScriptEngine engine = runtime.GetEngine("IronPython"); ScriptScope scope = engine.CreateScope(); //ScriptSource source = engine.CreateScriptSourceFromString("print 'Hello World'\r\na=1", SourceCodeKind.Statements); ScriptSource source = engine.CreateScriptSourceFromFile("glucodump/main.py"); source.Execute(scope); //Console.WriteLine(scope.GetVariable("cu")); }
public ScriptController(bool ADebug) { // _SearchPaths = new List<string>(); _setup = new ScriptRuntimeSetup(); _setup.DebugMode = true; _setup.LanguageSetups.Add(Python.CreateLanguageSetup(null)); _setup.DebugMode = ADebug; _runtime = new ScriptRuntime(_setup); _engine = _runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName); var bufOut = new BufferedStream(256, 100); _outputStream = bufOut; bufOut.OnFlushBuffer += new FlushBufferEvent(bufOut_OnFlushBuffer); _engine.Runtime.IO.SetOutput(bufOut, ASCIIEncoding.ASCII); _engine.Runtime.IO.SetErrorOutput(bufOut, ASCIIEncoding.ASCII); SetSearchPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); }
static void Main(string[] args) { // set path for dynamic assembly loading AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ResolveAssembly); string path = System.IO.Path.Combine(exe_path, py_path); pyscript = System.IO.Path.Combine(path, pyscript); pyscript = System.IO.Path.GetFullPath(pyscript); // normalize // get runtime ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup(); LanguageSetup language = Python.CreateLanguageSetup(null); language.Options["Debug"] = true; scriptRuntimeSetup.LanguageSetups.Add(language); ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup); // set sys.argv SetPyEnv(runtime, pyscript, args); // get engine ScriptScope scope = runtime.CreateScope(); ScriptEngine engine = runtime.GetEngine("python"); ScriptSource source = engine.CreateScriptSourceFromFile(pyscript); source.Compile(); try { source.Execute(scope); } catch (IronPython.Runtime.Exceptions.SystemExitException e) { Console.WriteLine(e.StackTrace); } }
protected override LanguageSetup /*!*/ CreateLanguageSetup() { return(Python.CreateLanguageSetup(null)); }