From b9efb87e428b478d929c297dca5ecd8c437b32e4 Mon Sep 17 00:00:00 2001 From: Cesare Montresor Date: Sat, 13 Jan 2024 14:57:11 +0100 Subject: [PATCH 1/2] - UOS syntax error now useful - editor catch output - multiline summary support - play from editor fixed --- Razor/RazorEnhanced/EnhancedScript.cs | 35 +++- .../RazorEnhanced/UI/EnhancedScriptEditor.cs | 29 ++- Razor/RazorEnhanced/UOSteamEngine.cs | 197 ++++++++++-------- 3 files changed, 166 insertions(+), 95 deletions(-) diff --git a/Razor/RazorEnhanced/EnhancedScript.cs b/Razor/RazorEnhanced/EnhancedScript.cs index e34be0ee..6f35807f 100644 --- a/Razor/RazorEnhanced/EnhancedScript.cs +++ b/Razor/RazorEnhanced/EnhancedScript.cs @@ -860,7 +860,8 @@ private bool LoadPython() content = File.ReadAllText(m_Script.Fullpath); } if (content == null || content == "") { - return false; } + return false; + } if (!pyEngine.Load(content, m_Script.Fullpath)) { return false; @@ -987,14 +988,27 @@ private bool LoadUOSteam() { uosEngine = new UOSteamEngine(); // Using // only will be deprecated instead of //UOS + + var content = m_Script.Text ?? ""; + if (content == "" && File.Exists(m_Script.Fullpath)) + { + content = File.ReadAllText(m_Script.Fullpath); + } + if (content == null || content == "") + { + return false; + } + + /* var text = System.IO.File.ReadAllLines(m_Script.Fullpath); if ((text[0].Substring(0, 2) == "//") && text[0].Length < 5) { string message = "WARNING: // header for UOS scripts is going to be deprecated. Please use //UOS instead"; SendOutput(message); } + */ - return uosEngine.Load(m_Script.Fullpath); + return uosEngine.Load(content, m_Script.Fullpath); } catch (Exception ex) { @@ -1007,6 +1021,23 @@ private bool RunUOSteam() try { uosEngine.SetTrace(TracebackUOS); + + uosEngine.SetStderr( + (string message) => { + Misc.SendMessage(message, 178); + if (m_stderrWriter == null) return; + m_stderrWriter.Invoke(message); + } + ); + + uosEngine.SetStdout( + (string message) => { + Misc.SendMessage(message); + if (m_stdoutWriter == null) return; + m_stdoutWriter.Invoke(message); + } + ); + uosEngine.Execute(); } catch (Exception ex) diff --git a/Razor/RazorEnhanced/UI/EnhancedScriptEditor.cs b/Razor/RazorEnhanced/UI/EnhancedScriptEditor.cs index 1855d6a8..79cec806 100644 --- a/Razor/RazorEnhanced/UI/EnhancedScriptEditor.cs +++ b/Razor/RazorEnhanced/UI/EnhancedScriptEditor.cs @@ -226,6 +226,7 @@ internal EnhancedScriptEditor(string filename, string filetype = ".py") m_Script.ScriptEngine.SetTracebackPython(null); } m_Script.ScriptEngine.SetStdout(this.SetErrorBox); + m_Script.ScriptEngine.SetStderr(this.SetErrorBox); // Always have to make these or Open() wont work from UOS to PY // m_pe = new PythonEngine(this.SetErrorBox); // m_pe.Engine.SetTrace(null); @@ -535,10 +536,18 @@ public void InitPythonSyntaxHighlight() { m_popupMenu.Items.MaximumSize = new Size(m_popupMenu.Items.Width + 20, m_popupMenu.Items.Height); m_popupMenu.Items.Width = m_popupMenu.Items.Width + 20; + } + private void OnTraceback(string line, int line_num) + { + } + private void OnTracebackUOS(TraceBackFrame frame, string result, object payload) + { + + } - private TracebackDelegate OnTraceback(TraceBackFrame frame, string result, object payload) + private TracebackDelegate OnTracebackPy(TraceBackFrame frame, string result, object payload) { if (m_Debugger) { @@ -586,7 +595,7 @@ private TracebackDelegate OnTraceback(TraceBackFrame frame, string result, objec } } - return OnTraceback; + return OnTracebackPy; } else return null; @@ -597,7 +606,7 @@ private void TracebackCall() SetStatusLabel("DEBUGGER ACTIVE - " + string.Format("Call {0}", m_CurrentCode.co_name), Color.YellowGreen); SetHighlightLine((int)m_CurrentFrame.f_lineno - 1, Color.LightGreen); string locals = GetLocalsText(m_CurrentFrame); - SetTraceback(locals); + SetTracebackOutput(locals); } private void TracebackReturn() @@ -605,7 +614,7 @@ private void TracebackReturn() SetStatusLabel("DEBUGGER ACTIVE - " + string.Format("Return {0}", m_CurrentCode.co_name), Color.YellowGreen); SetHighlightLine((int)m_CurrentFrame.f_lineno - 1, Color.LightBlue); string locals = GetLocalsText(m_CurrentFrame); - SetTraceback(locals); + SetTracebackOutput(locals); } private void TracebackLine() @@ -613,14 +622,14 @@ private void TracebackLine() SetStatusLabel("DEBUGGER ACTIVE - " + string.Format("Line {0}", (int)m_CurrentFrame.f_lineno), Color.YellowGreen); SetHighlightLine((int)m_CurrentFrame.f_lineno - 1, Color.Yellow); string locals = GetLocalsText(m_CurrentFrame); - SetTraceback(locals); + SetTracebackOutput(locals); } private void TracebackBreakpoint() { SetStatusLabel("DEBUGGER ACTIVE - " + string.Format("Breakpoint at line {0}", (int)m_CurrentFrame.f_lineno), Color.YellowGreen); string locals = GetLocalsText(m_CurrentFrame); - SetTraceback(locals); + SetTracebackOutput(locals); } private void EnqueueCommand(Command command) @@ -677,7 +686,7 @@ private void Start(bool debugger) { default: case ScriptLanguage.PYTHON: - m_Script.ScriptEngine.SetTracebackPython(OnTraceback); + m_Script.ScriptEngine.SetTracebackPython(OnTracebackPy); break; case ScriptLanguage.CSHARP: if (m_Script.HasValidPath) @@ -710,7 +719,7 @@ private void Stop() fastColoredTextBoxEditor.Invalidate(); SetStatusLabel("IDLE", Color.DarkTurquoise); - SetTraceback(String.Empty); + SetTracebackOutput(String.Empty); m_Script.Stop(); SetErrorBox("STOP: " + m_Script.Fullpath); @@ -811,14 +820,14 @@ private string GetLocalsText(TraceBackFrame frame) return result; } - private void SetTraceback(string text) + private void SetTracebackOutput(string text) { if (this.m_onclosing) return; if (this.textBoxDebug.InvokeRequired) { - SetTracebackDelegate d = new SetTracebackDelegate(SetTraceback); + SetTracebackDelegate d = new SetTracebackDelegate(SetTracebackOutput); this.Invoke(d, new object[] { text }); } else diff --git a/Razor/RazorEnhanced/UOSteamEngine.cs b/Razor/RazorEnhanced/UOSteamEngine.cs index 9556529c..cbcc8ab7 100644 --- a/Razor/RazorEnhanced/UOSteamEngine.cs +++ b/Razor/RazorEnhanced/UOSteamEngine.cs @@ -1,4 +1,5 @@ using Accord.Math; +using Assistant; using IronPython.Runtime; using Microsoft.Scripting.Utils; using System; @@ -32,10 +33,23 @@ public class UOSteamEngine private Interpreter m_Interpreter; private Script m_Script; + private Action m_OutputWriter; + private Action m_ErrorWriter; + public void SetTrace(UOSTracebackDelegate traceDelegate) { m_Script.OnTraceback += traceDelegate; } + public void SetStdout(Action stdoutWriter) + { + m_OutputWriter = stdoutWriter; + } + + public void SetStderr(Action stderrWriter) + { + m_ErrorWriter = stderrWriter; + } + public Script Script { get { return m_Script; } } public Interpreter Interpreter { get { return m_Interpreter; } } public Namespace Namespace { @@ -95,7 +109,7 @@ internal List AllKeywords() } else { - retlist.Add(methodSummary); + retlist.AddRange(methodSummary.Split('\n').Where(line => line.Trim().Length > 0)); } } @@ -116,7 +130,7 @@ internal List AllKeywords() } else { - retlist.Add(methodSummary); + retlist.AddRange(methodSummary.Split('\n').Where(line=>line.Trim().Length>0)); } } return retlist; @@ -138,7 +152,19 @@ public UOSteamEngine() UpdateNamespace(); } - + public void SendOutput(string text) + { + if (m_OutputWriter != null) { + m_OutputWriter.Invoke(text); + } + } + public void SendError(string text) + { + if (m_ErrorWriter != null) + { + m_ErrorWriter.Invoke(text); + } + } private void RegisterAlias() { m_Interpreter.RegisterAliasHandler("ground", AliasHandler); @@ -211,28 +237,29 @@ public bool Load(string filename) try { var root = m_Lexer.Lex(filename); - return Load(root, Misc.SendMessage, filename); + return Load(root, filename); } catch (Exception e){ - Misc.SendMessage($"UOSEngine: fail to parse script:\n{e.Message}"); + SendError($"UOSEngine: fail to parse script:\n{e.Message}"); } return false; } - public bool Load(string[] textLines, Action writer, string filename = "") + public bool Load(string content, string filename = "") { try { - var root = m_Lexer.Lex(textLines); - return Load(root, writer, filename); + var lines = content.Split('\n'); + var root = m_Lexer.Lex(lines); + return Load(root, filename); } catch (Exception e){ - Misc.SendMessage($"UOSEngine: fail to parse script:\n{e.Message}"); + SendOutput($"UOSEngine: fail to parse script:\n{e.Message}"); } return false; } - public bool Load(ASTNode root, Action writer, string filename = "") + public bool Load(ASTNode root, string filename = "") { m_mutex.WaitOne(); @@ -242,7 +269,7 @@ public bool Load(ASTNode root, Action writer, string filename = "") { InitInterpreter(true); - m_Script = new Script(root, writer, this); + m_Script = new Script(root, this); m_Script.Filename = filename; @@ -250,7 +277,7 @@ public bool Load(ASTNode root, Action writer, string filename = "") m_Loaded = true; } catch (Exception e){ - Misc.SendMessage($"UOSEngine: fail to load script:\n{e.Message}"); + SendOutput($"UOSEngine: fail to load script:\n{e.Message}"); } m_mutex.ReleaseMutex(); @@ -306,10 +333,11 @@ private void Execute() { while (m_Interpreter.ExecuteScript()) { }; } - catch (Exception) + catch (Exception e) { m_Interpreter.StopScript(); - throw; + SendError(e.Message); + //throw e; } finally { @@ -644,7 +672,7 @@ private IComparable ListExists(string expression, Argument[] args, bool quiet) /// /// useobject (serial) /// - private static IComparable UseObjExp(string expression, Argument[] args, bool quiet) + private IComparable UseObjExp(string expression, Argument[] args, bool quiet) { UseObject(expression, args, quiet, false); return true; @@ -1974,11 +2002,11 @@ private static bool Info(string command, Argument[] args, bool quiet, bool force /// /// setability ('primary'/'secondary'/'stun'/'disarm') ['on'/'off'] /// - private static bool SetAbility(string command, Argument[] args, bool quiet, bool force) + private bool SetAbility(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 2) { - Misc.SendMessage("set ability not proper syntax"); + SendError("set ability not proper syntax"); return true; } string ability = args[0].AsString().ToLower(); @@ -2076,11 +2104,11 @@ private static bool Walk(string command, Argument[] args, bool quiet, bool force /// /// pathfindto x y /// - private static bool PathFindTo(string command, Argument[] args, bool quiet, bool force) + private bool PathFindTo(string command, Argument[] args, bool quiet, bool force) { if (args.Length != 2) { - Misc.SendMessage("pathfindto requires an X and Y co-ordinates"); + SendError("pathfindto requires an X and Y co-ordinates"); return false; } @@ -2174,11 +2202,11 @@ private static bool BandageSelf(string command, Argument[] args, bool quiet, boo /// /// usetype (graphic) [color] [source] [range or search level] /// - private static IComparable UseType(string command, Argument[] args, bool quiet) + private IComparable UseType(string command, Argument[] args, bool quiet) { if (args.Length == 0) { - Misc.SendMessage("Insufficient parameters"); + SendError("Insufficient parameters"); return false; } int itemID = args[0].AsInt(); @@ -2213,11 +2241,11 @@ private static IComparable UseType(string command, Argument[] args, bool quiet) /// /// useobject (serial) /// - private static bool UseObject(string command, Argument[] args, bool quiet, bool force) + private bool UseObject(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 0) { - Misc.SendMessage("Insufficient parameters"); + SendError("Insufficient parameters"); return true; } Assistant.Serial serial = (int)args[0].AsSerial(); @@ -2260,7 +2288,7 @@ private bool UseOnce(string command, Argument[] args, bool quiet, bool force) // Current logic for us, only searches 1 deep .. maybe thats enough for now if (args.Length == 0) { - Misc.SendMessage("Insufficient parameters"); + SendError("Insufficient parameters"); return true; } @@ -2303,11 +2331,11 @@ private bool CleanUseQueue(string command, Argument[] args, bool quiet, bool for /// /// (serial) (destination) [(x, y, z)] [amount] /// - private static bool MoveItem(string command, Argument[] args, bool quiet, bool force) + private bool MoveItem(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 2) { - Misc.SendMessage("Insufficient parameters"); + SendError("Insufficient parameters"); return true; } int source = (int)args[0].AsSerial(); @@ -2336,7 +2364,7 @@ private static bool MoveItem(string command, Argument[] args, bool quiet, bool f /// /// useskill ('skill name'/'last') /// - private static bool UseSkill(string command, Argument[] args, bool quiet, bool force) + private bool UseSkill(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 1) { @@ -2351,7 +2379,7 @@ private static bool UseSkill(string command, Argument[] args, bool quiet, bool f } else { - Misc.SendMessage("Incorrect number of parameters"); + SendError("Incorrect number of parameters"); } return true; } @@ -2362,11 +2390,11 @@ private static bool UseSkill(string command, Argument[] args, bool quiet, bool f /// /// Feed doesn't support food groups etc unless someone adds it /// Config has the data now - private static bool Feed(string command, Argument[] args, bool quiet, bool force) + private bool Feed(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 2) { - Misc.SendMessage("Insufficient parameters"); + SendError("Insufficient parameters"); return false; } int target = (int)args[0].AsSerial(); @@ -2396,11 +2424,11 @@ private static bool Feed(string command, Argument[] args, bool quiet, bool force /// /// rename (serial) ('name') /// - private static bool RenamePet(string command, Argument[] args, bool quiet, bool force) + private bool RenamePet(string command, Argument[] args, bool quiet, bool force) { if (args.Length != 2) { - Misc.SendMessage("Incorrect parameters"); + SendError("Incorrect parameters"); return true; } int serial = (int)args[0].AsSerial(); @@ -2592,7 +2620,7 @@ private bool PushList(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 2) { - Misc.SendMessage("Usage: pushlist ('list name') ('element name') ('front'/'back']"); + SendError("Usage: pushlist ('list name') ('element name') ('front'/'back']"); throw new RunTimeError(null, "Usage: pushlist ('list name') ('element name') ('front'/'back']"); // return true; } @@ -2901,7 +2929,7 @@ private static bool EquipWand(string command, Argument[] args, bool quiet, bool /// /// buy ('list name') /// - private static bool Buy(string command, Argument[] args, bool quiet, bool force) + private bool Buy(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 1) { @@ -2913,7 +2941,7 @@ private static bool Buy(string command, Argument[] args, bool quiet, bool force) } else { - Misc.SendMessage(String.Format("Buy List {0} does not exist", buyListName), 55); + SendError(String.Format("Buy List {0} does not exist", buyListName)); } } @@ -2923,7 +2951,7 @@ private static bool Buy(string command, Argument[] args, bool quiet, bool force) /// /// sell ('list name') /// - private static bool Sell(string command, Argument[] args, bool quiet, bool force) + private bool Sell(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 1) { @@ -2935,7 +2963,7 @@ private static bool Sell(string command, Argument[] args, bool quiet, bool force } else { - Misc.SendMessage(String.Format("Sell List {0} does not exist", sellListName), 55); + SendError(String.Format("Sell List {0} does not exist", sellListName)); } } @@ -3062,7 +3090,7 @@ private static bool Autoloot(string command, Argument[] args, bool quiet, bool f /// /// dress ['profile name'] /// - private static bool Dress(string command, Argument[] args, bool quiet, bool force) + private bool Dress(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 1) @@ -3074,7 +3102,7 @@ private static bool Dress(string command, Argument[] args, bool quiet, bool forc } else { - Misc.SendMessage(String.Format("Dress List {0} does not exist", dressListName), 55); + SendError(String.Format("Dress List {0} does not exist", dressListName)); } } RazorEnhanced.Dress.DressFStart(); @@ -3084,7 +3112,7 @@ private static bool Dress(string command, Argument[] args, bool quiet, bool forc /// /// undress ['profile name'] /// - private static bool Undress(string command, Argument[] args, bool quiet, bool force) + private bool Undress(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 1) @@ -3096,7 +3124,7 @@ private static bool Undress(string command, Argument[] args, bool quiet, bool fo } else { - Misc.SendMessage(String.Format("UnDress List {0} does not exist", unDressListName), 55); + SendError(String.Format("UnDress List {0} does not exist", unDressListName)); } } RazorEnhanced.Dress.UnDressFStart(); @@ -3196,7 +3224,7 @@ private static bool ReplyGump(string command, Argument[] args, bool quiet, bool /// /// closegump 'container' 'serial' /// - private static bool CloseGump(string command, Argument[] args, bool quiet, bool force) + private bool CloseGump(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 2) @@ -3209,7 +3237,7 @@ private static bool CloseGump(string command, Argument[] args, bool quiet, bool } else { - Misc.SendMessage(String.Format("Unable to closegumps on {0} type objects", container), 55); + SendError(String.Format("Unable to closegumps on {0} type objects", container)); } } return true; @@ -3399,11 +3427,11 @@ internal static void RightMouseClick(int xpos, int ypos) /// /// clickscreen (x) (y) ['single'/'double'] ['left'/'right'] /// - private static bool ClickScreen(string command, Argument[] args, bool quiet, bool force) + private bool ClickScreen(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 2) { - Misc.SendMessage("Invalid parameters", 55); + SendError("Invalid parameters"); return true; } int x = args[0].AsInt(); @@ -3565,11 +3593,11 @@ private static bool YellMsg(string command, Argument[] args, bool quiet, bool fo /// /// location (serial) /// - private static bool Location(string command, Argument[] args, bool quiet, bool force) + private bool Location(string command, Argument[] args, bool quiet, bool force) { uint serial = args[0].AsSerial(); Mobile m = Mobiles.FindBySerial((int)serial); - Misc.SendMessage(String.Format("Position({0}, {1})", m.Position.X, m.Position.Y), 32, false); + SendOutput(String.Format("Position({0}, {1})", m.Position.X, m.Position.Y)); return true; } @@ -3577,7 +3605,7 @@ private static bool Location(string command, Argument[] args, bool quiet, bool f /// /// sysmsg (text) [color] /// - private static bool SysMsg(string command, Argument[] args, bool quiet, bool force) + private bool SysMsg(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 1) { @@ -3743,11 +3771,11 @@ private static bool ContextMenu(string command, Argument[] args, bool quiet, boo /// /// waitforcontext (serial) (option) (timeout) /// - private static bool WaitForContext(string command, Argument[] args, bool quiet, bool force) + private bool WaitForContext(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 2) { - Misc.SendMessage("Usage is waitforcontents serial contextSelection timeout"); + SendError("Usage is waitforcontents serial contextSelection timeout"); WrongParameterCount(command, 2, args.Length, "waitforcontents serial contextSelection timeout"); } int timeout = 5000; @@ -3850,11 +3878,11 @@ private static bool WaitForProperties(string command, Argument[] args, bool quie /// /// autocolorpick (color) (dyesSerial) (dyeTubSerial) /// - private static bool AutoColorPick(string command, Argument[] args, bool quiet, bool force) + private bool AutoColorPick(string command, Argument[] args, bool quiet, bool force) { if (args.Length != 3) { - Misc.SendMessage("Usage is: autocolorpick color dyesSerial dyeTubSerial"); + SendError("Usage is: autocolorpick color dyesSerial dyeTubSerial"); WrongParameterCount(command, 3, args.Length, "Usage is: autocolorpick color dyesSerial dyeTubSerial"); } @@ -3863,8 +3891,8 @@ private static bool AutoColorPick(string command, Argument[] args, bool quiet, b uint dyeTubSerial = args[2].AsSerial(); Item dyes = Items.FindBySerial((int)dyesSerial); Item dyeTub = Items.FindBySerial((int)dyeTubSerial); - if (dyes == null) { Misc.SendMessage("autocolorpick: error: can't find dyes with serial " + dyesSerial); } - if (dyeTub == null) { Misc.SendMessage("autocolorpick: error: can't find dye tub with serial " + dyeTubSerial); } + if (dyes == null) { SendError("autocolorpick: error: can't find dyes with serial " + dyesSerial); } + if (dyeTub == null) { SendError("autocolorpick: error: can't find dye tub with serial " + dyeTubSerial); } if (dyes != null && dyeTub != null) { Items.ChangeDyeingTubColor(dyes, dyeTub, color); @@ -3965,7 +3993,7 @@ private static bool BigHeal(string command, Argument[] args, bool quiet, bool fo /// /// cast (spell id/'spell name'/'last') [serial] /// - private static bool Cast(string command, Argument[] args, bool quiet, bool force) + private bool Cast(string command, Argument[] args, bool quiet, bool force) { if (args.Length == 1) { @@ -3980,7 +4008,7 @@ private static bool Cast(string command, Argument[] args, bool quiet, bool force } else { - Misc.SendMessage("Incorrect number of parameters"); + SendError("Incorrect number of parameters"); } @@ -4248,8 +4276,9 @@ private bool GetFriend(string command, Argument[] args, bool quiet, bool force) } return true; } - + /// /// script ('run'|'stop'|'suspend'|'resume'|'isrunning'|'issuspended') [script_name] [output_alias] + /// private bool ManageScripts(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 1) { WrongParameterCount(command, 1, args.Length); } @@ -4339,10 +4368,10 @@ private bool ManageNamespaces_List(string command, Argument[] args, bool quiet, //} //else //{ } - Misc.SendMessage("Namespaces:"); + SendOutput("Namespaces:"); foreach (var name in Namespace.List()) { - Misc.SendMessage(name); + SendOutput(name); } // return true; @@ -4437,7 +4466,7 @@ private bool ManageNamespaces_Print(string command, Argument[] args, bool quiet, { throw new IllegalArgumentException($"{cmd} items kind must be either: 'all', 'alias', 'lists', 'timers' "); } - Misc.SendMessage(content); + SendOutput(content); return true; } private bool ManageNamespaces_SetGet(string command, Argument[] args, bool quiet, bool force) @@ -4490,7 +4519,7 @@ private bool ManageNamespaces_SetGet(string command, Argument[] args, bool quiet /// /// targettype (graphic) [color] [range] /// - private static bool TargetType(string command, Argument[] args, bool quiet, bool force) + private bool TargetType(string command, Argument[] args, bool quiet, bool force) { // targettype (graphic) [color] [range] if (args.Length == 0) { WrongParameterCount(command, 1, 0);} @@ -4524,7 +4553,7 @@ private static bool TargetType(string command, Argument[] args, bool quiet, bool if (itm == null) { - if (!quiet) { Misc.SendMessage("targettype: graphic "+ graphic.ToString() + " not found in range " + range.ToString() ); } + if (!quiet) { SendError("targettype: graphic "+ graphic.ToString() + " not found in range " + range.ToString() ); } } else { RazorEnhanced.Target.TargetExecute(itm); @@ -4536,7 +4565,7 @@ private static bool TargetType(string command, Argument[] args, bool quiet, bool /// /// targetground (graphic) [color] [range] /// - private static bool TargetGround(string command, Argument[] args, bool quiet, bool force) + private bool TargetGround(string command, Argument[] args, bool quiet, bool force) { // targettype (graphic) [color] [range] if (args.Length == 0) { WrongParameterCount(command, 1, 0); } @@ -4564,7 +4593,7 @@ private static bool TargetGround(string command, Argument[] args, bool quiet, bo if (itm == null) { - if (!quiet) { Misc.SendMessage("targettype: graphic " + graphic.ToString() + " not found in range " + range.ToString()); } + if (!quiet) { SendError("targettype: graphic " + graphic.ToString() + " not found in range " + range.ToString()); } } else { @@ -4579,7 +4608,7 @@ private static bool TargetGround(string command, Argument[] args, bool quiet, bo /// /// targettile ('last'/'current'/(x y z)) [graphic] /// - private static bool TargetTile(string command, Argument[] args, bool quiet, bool force) + private bool TargetTile(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 1) { WrongParameterCount(command, 1, args.Length); } if (args.Length == 2 || args.Length == 4) // then graphic specified just use it @@ -4601,7 +4630,7 @@ private static bool TargetTile(string command, Argument[] args, bool quiet, bool } if (itm == null) { - if (!quiet) { Misc.SendMessage("targettile: graphic " + graphic.ToString() + " not found"); } + if (!quiet) { SendError("targettile: graphic " + graphic.ToString() + " not found"); } } else { @@ -4648,7 +4677,7 @@ private static bool TargetTile(string command, Argument[] args, bool quiet, bool /// /// targettileoffset (x y z) [graphic] /// - private static bool TargetTileOffset(string command, Argument[] args, bool quiet, bool force) + private bool TargetTileOffset(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 3) { WrongParameterCount(command, 3, args.Length); } if (args.Length == 4) // then graphic specified just use it @@ -4668,7 +4697,7 @@ private static bool TargetTileOffset(string command, Argument[] args, bool quiet } if (itm == null) { - if (!quiet) { Misc.SendMessage("targettile: graphic " + graphic.ToString() + " not found"); } + if (!quiet) { SendError("targettile: graphic " + graphic.ToString() + " not found"); } } else { @@ -4702,7 +4731,7 @@ private static bool TargetTileOffset(string command, Argument[] args, bool quiet /// /// targettilerelative (serial) (range) [reverse = 'true' or 'false'] [graphic] /// - private static bool TargetTileRelative(string command, Argument[] args, bool quiet, bool force) + private bool TargetTileRelative(string command, Argument[] args, bool quiet, bool force) { // targettilerelative (serial) (range) [reverse = 'true' or 'false'] [graphic] if (args.Length < 2) { WrongParameterCount(command, 2, args.Length); } @@ -4745,7 +4774,7 @@ private static bool TargetTileRelative(string command, Argument[] args, bool qui { if (!quiet) { - Misc.SendMessage("targettilerelative: graphic " + graphic.ToString() + " not found in range " + range.ToString()); + SendError("targettilerelative: graphic " + graphic.ToString() + " not found in range " + range.ToString()); } } else @@ -4856,10 +4885,10 @@ public static String BuildErrorMessage(ASTNode node, string error) { string msg = string.Format("Error:\t{0}\n", error); if (node != null) { - msg += String.Format("Type:\t{0}\n", node.Type); - msg += String.Format("Word:\t{0}\n", node.Lexeme); - msg += String.Format("Line:\t{0}\n", node.LineNumber + 1); - msg += String.Format("Code:\t{0}\n", node.Lexer.GetLine(node.LineNumber)); + msg += String.Format("Type: {0}\n", node.Type); + msg += String.Format("Word: {0}\n", node.Lexeme); + msg += String.Format("Line: {0}\n", node.LineNumber + 1); + msg += String.Format("Code: {0}\n", node.Lexer.GetLine(node.LineNumber)); } return msg; } @@ -5192,7 +5221,7 @@ public class Script bool Debug { get; set; } public string Filename; public UOSteamEngine Engine; - Action debugWriter; + Action DebugWriter; public event UOSTracebackDelegate OnTraceback; @@ -5277,9 +5306,8 @@ private Argument[] ConstructArguments(ref ASTNode node) // scripts to a bytecode. That would allow more errors // to be caught with better error messages, as well as // make the scripts execute more quickly. - public Script(ASTNode root, Action writer, UOSteamEngine engine) + public Script(ASTNode root, UOSteamEngine engine) { - debugWriter = writer; // Set current to the first statement _root = root; Engine = engine; @@ -5890,8 +5918,8 @@ public void Advance() _statement = _statement.Next(); if (Debug) { - if (_statement != null) - debugWriter(String.Format("Line: {0}", _statement.LineNumber+1)); + if (_statement != null && DebugWriter!=null) + DebugWriter(String.Format("Line: {0}", _statement.LineNumber+1)); } } @@ -6377,7 +6405,7 @@ public class Interpreter internal ConcurrentDictionary> _lists { get { return m_Engine.Namespace._lists; } } - // Lists + // Lists private UOSteamEngine m_Engine; private Script m_Script = null; @@ -6677,6 +6705,7 @@ public bool StartScript() m_Script = m_Engine.Script; _executionState = ExecutionState.RUNNING; + Suspended = false; m_Script.Init(); ExecuteScript(); @@ -6686,6 +6715,7 @@ public bool StartScript() public void StopScript() { m_Script = null; + Suspended = false; _executionState = ExecutionState.RUNNING; } @@ -6887,10 +6917,11 @@ public ASTNode(ASTNodeType type, string lexeme, ASTNode parent, int lineNumber, Lexeme = ""; Parent = parent; LineNumber = lineNumber; - if (lexer == null) { - this.Lexer = parent.Lexer; + if (lexer == null && parent != null && parent.Lexer != null) + { + lexer = parent.Lexer; } - + this.Lexer = lexer; } public ASTNode Push(ASTNodeType type, string lexeme, int lineNumber) From 1b8287c5ff7805adcbd80b06de3bbea49c42bd1c Mon Sep 17 00:00:00 2001 From: Cesare Montresor Date: Sat, 13 Jan 2024 14:57:41 +0100 Subject: [PATCH 2/2] - version bump --- Razor/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Razor/Properties/AssemblyInfo.cs b/Razor/Properties/AssemblyInfo.cs index 087f3499..a3d84afd 100644 --- a/Razor/Properties/AssemblyInfo.cs +++ b/Razor/Properties/AssemblyInfo.cs @@ -26,7 +26,7 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.8.2.105")] +[assembly: AssemblyVersion("0.8.2.106")] // // In order to sign your assembly you must specify a key to use. Refer to the