public DebugForm() { InitializeComponent(); try { // why is the script engine remembering my imports? oh well, it's handy :P PythonScriptEngine.EvaluateExpression <object>("from FrEee.Modding import Mod"); rtbOutput.AppendText("Imported Mod.\n"); rtbOutput.AppendText("Mod.Current is currently: " + OrNil(Mod.Current) + "\n"); PythonScriptEngine.EvaluateExpression <object>("from FrEee.Game.Objects.Space import Galaxy"); rtbOutput.AppendText("Imported Galaxy.\n"); rtbOutput.AppendText("Galaxy.Current is currently: " + OrNil(Galaxy.Current) + "\n"); PythonScriptEngine.EvaluateExpression <object>("from FrEee.Game.Objects.Civilization import Empire"); rtbOutput.AppendText("Imported Empire.\n"); rtbOutput.AppendText("Empire.Current is currently: " + OrNil(Empire.Current) + "\n"); if (Mod.Current != null) { PythonScriptEngine.EvaluateExpression <object>(Mod.Current.GlobalScript.FullText); rtbOutput.AppendText("Ran mod global script.\n"); } } catch (Exception ex) { rtbOutput.AppendText("Error initializing debug console.\n"); rtbOutput.AppendText(ex + "\n"); } }
/// <summary> /// Makes this event happen right now. /// </summary> public void Execute() { foreach (var m in Template.OccurrenceMessages) { foreach (var emp in AffectedEmpires) { var context = new SafeDictionary <string, object>(); var text = m.Text.Evaluate(context); emp.RecordLog(this, text, LogMessages.LogMessageType.Generic); } } var dict = new SafeDictionary <string, object>(); dict.Add("target", Target); // SE4/SE5 style replacement strings turn into dynamic formulas var regex = new Regex(@"\[\%(.*?)\%?\]"); var matches = regex.Matches(Template.Type.Action.Text); foreach (Match m in matches) { dict.Add(m.Captures[0].Value, new ComputedFormula <string>(m.Captures[0].Value, this, true).Value); } PythonScriptEngine.RunScript(Template.Type.Action, dict); }
public void InitTestScriptEngine() { var lgf = LoggerFactory.Create(f => { f.AddConsole(); }); _js_engine = new JavaScriptEngine(lgf.CreateLogger <JavaScriptEngine>(), Options.Create(new Interpreter.EngineSetting() { Timeout = 4 })); _python_engine = new PythonScriptEngine(lgf.CreateLogger <PythonScriptEngine>(), Options.Create(new Interpreter.EngineSetting() { Timeout = 4 })); _lua_engine = new LuaScriptEngine(lgf.CreateLogger <LuaScriptEngine>(), Options.Create(new Interpreter.EngineSetting() { Timeout = 4 })); _c_engine = new CScriptEngine(lgf.CreateLogger <CScriptEngine>(), Options.Create(new Interpreter.EngineSetting() { Timeout = 4 })); _sql_engine = new SQLEngine(lgf.CreateLogger <SQLEngine>(), Options.Create(new Interpreter.EngineSetting() { Timeout = 4 })); _csharp_engine = new CSharpScriptEngine(lgf.CreateLogger <CSharpScriptEngine>(), Options.Create(new Interpreter.EngineSetting() { Timeout = 4 })); }
public void EvaluateExpression() { var expr = "x * y"; var variables = new Dictionary <string, object>(); variables.Add("x", 6); variables.Add("y", 7); Assert.AreEqual(42, PythonScriptEngine.EvaluateExpression <int>(expr, variables)); }
public override void Act(TDomain domain, TContext context, SafeDictionary <string, ICollection <string> > EnabledMinisters) { var variables = new Dictionary <string, object>(); variables.Add("domain", domain); var readOnlyVariables = new Dictionary <string, object>(); readOnlyVariables.Add("context", context); readOnlyVariables.Add("enabledMinisters", EnabledMinisters); PythonScriptEngine.RunScript <object>(Script as PythonScript, variables, readOnlyVariables); }
private void btnSubmit_Click(object sender, EventArgs e) { rtbOutput.SelectionColor = Color.Green; rtbOutput.AppendText(">" + txtCommand.Text + "\n"); rtbOutput.SelectionColor = rtbOutput.ForeColor; try { var result = PythonScriptEngine.EvaluateExpression <object>("str(" + txtCommand.Text + ")"); rtbOutput.AppendText(OrNil(result)); rtbOutput.AppendText("\n"); } catch (Exception ex) { rtbOutput.AppendText("Exception has occurred.\n"); rtbOutput.AppendText(ex + "\n"); } rtbOutput.ScrollToCaret(); txtCommand.Text = ""; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PythonScriptEngine obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public virtual void Sync(EnginePtr exeeng, Direct3D exed3d, OpenGL exeogl, Havok exehvk, GuiFactory exegui, Forms exefms, DirectIpt exedip, WinIpt exewip, FFmpeg exeffm, CryptoPP execpp, ID3Lib exeid3, WinAudio exewad, XAudio2 exexa2, WinMidi exemid, WinSock exewsk, AsyncWorkers exeaws, SQLite exesql, HaruPdf exepdf, RayTracer exertr, Pbrt exepbrt, PythonScriptEngine exepse, Console execle) { IronSightEnginePINVOKE.IDirect3D_Sync(swigCPtr, EnginePtr.getCPtr(exeeng), Direct3D.getCPtr(exed3d), OpenGL.getCPtr(exeogl), Havok.getCPtr(exehvk), GuiFactory.getCPtr(exegui), Forms.getCPtr(exefms), DirectIpt.getCPtr(exedip), WinIpt.getCPtr(exewip), FFmpeg.getCPtr(exeffm), CryptoPP.getCPtr(execpp), ID3Lib.getCPtr(exeid3), WinAudio.getCPtr(exewad), XAudio2.getCPtr(exexa2), WinMidi.getCPtr(exemid), WinSock.getCPtr(exewsk), AsyncWorkers.getCPtr(exeaws), SQLite.getCPtr(exesql), HaruPdf.getCPtr(exepdf), RayTracer.getCPtr(exertr), Pbrt.getCPtr(exepbrt), PythonScriptEngine.getCPtr(exepse), Console.getCPtr(execle)); if (IronSightEnginePINVOKE.SWIGPendingException.Pending) { throw IronSightEnginePINVOKE.SWIGPendingException.Retrieve(); } }
public void CallFunction() { var script = new PythonScript("test", "def square(x):\n\treturn x ** 2;"); Assert.AreEqual(64, PythonScriptEngine.CallFunction <int>(script, "square", 8)); }
public ScriptableSystem(params Type[] componentTypes) { _pythonEngine = new PythonScriptEngine(GetType().Name + ".py"); }