public void ExecutePythonCode(string code) { pySource = pyEngine.CreateScriptSourceFromString(code,SourceCodeKind.InteractiveCode); object output = pySource.Execute(pyScope); if (output != null) Console.Echo(pyEngine.Operations.Format(output)); ShowResults(); }
public ReplayReader() { // Lib should be in SearchPath, but we need to add our own python files as well ICollection<string> paths = m_engine.GetSearchPaths(); paths.Add(m_blizzScriptPath); m_engine.SetSearchPaths(paths); // create global scope, we only need 1 of those m_scope = m_engine.CreateScope(); // load our API file we're going to communicate with m_source = m_engine.CreateScriptSourceFromFile(m_blizzScriptPath + m_replayLibPyFile); m_source.Execute(m_scope); }
private void Compile() { try { _source = _engine.CreateScriptSourceFromString("import clr" + Environment.NewLine + "clr.AddReference('mtrand')" + Environment.NewLine); _source.Execute(_scope); _source = _engine.CreateScriptSourceFromString(textBox_CodeIn.Text); dynamic res2 = _source.Execute(_scope); if (res2 != null) textBox_CodeOut.Text += Environment.NewLine + ">>> " + _builtin.str(res2); textBox_CodeOut.SelectionStart = textBox_CodeOut.TextLength; } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Error compile"); } toolStripStatusLabel.Text = "Compile done"; }
protected override int RunFile(ScriptSource source) { if (this.ScriptScope == null) { this.ScriptScope = this.Engine.CreateScope(); this.ScriptScope.SetVariable( "time", AFunc.Create( "time", (Func<Aplus, AType>)Time, 1, "returns the user time of the current process" ) ); } try { AType result = source.Execute<AType>(this.ScriptScope); Console.WriteLine(result.ToString(), Style.Out); } catch (Error error) { Console.ErrorOutput.Write(error); return 1; } catch (Exception) { throw; } return 0; }
protected void LoadFile(ScriptSource source) { AType result; try { result = source.Execute<AType>(this.ScriptScope); } catch (Exception e) { UnhandledException(e); } }
private int GetResult(ScriptEngine engine, ScriptSource source) { var scope = engine.CreateScope(); return engine.Operations.ConvertTo<int>(source.Execute(scope) ?? 0); }