/// <summary> /// Called on python console command. /// </summary> public static string PythonCommand(string[] args, IDictionary <string, string> namedArgs) { if (args.Length == 0) { return("Executes a Python expression."); } if (Script.Python == null) { return("Python engine not initialized."); } var expression = args.Aggregate("", (current, t) => current + (t + " ")); try { var result = Script.Python.Execute(expression); return(result?.ToString() ?? ""); } catch (Exception e) { if (e.InnerException != null) { e = e.InnerException; } Debug.Log("<b><color=#FF0000>Python error: " + e.Message + "</color></b>\n" + PythonEnvironment.FormatException(e)); return(""); } }
/// <summary> /// Loads mod's scripting features. /// </summary> public static void LoadScripter() { if (LoadedScripter) { throw new InvalidOperationException("Mod's scripting features already loaded."); } if (PythonEnvironment.LoadPythonAssembly()) { PythonEnvironment.InitializeEngine(); PythonEnvironment.ScripterEnvironment = new PythonEnvironment(); ModConsole.AddMessage(LogType.Log, "[LenchScripterMod]: " + PythonEnvironment.ScripterEnvironment.Execute("sys.version")); LoadedScripter = true; } }