BadScript 2
Loading...
Searching...
No Matches
BadScriptDebugger.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
5
10
15{
19 private readonly Dictionary<string, int> m_LineNumbers = new Dictionary<string, int>();
20
24 private readonly BadRuntime m_Runtime;
25
29 private readonly List<string> m_SeenFiles = new List<string>();
30
36 public BadScriptDebugger(BadRuntime runtime, string debuggerPath)
37 {
38 m_Runtime = runtime
39 .Clone()
40 .UseApi(new BadScriptDebuggerApi(this, debuggerPath));
41 LoadDebugger(debuggerPath);
42 }
43
49 {
50 m_Runtime = runtime
51 .Clone()
52 .UseApi(new BadScriptDebuggerApi(this));
53
54
56 }
57
59 public void Step(BadDebuggerStep stepInfo)
60 {
61 stepInfo.GetLines(4, 4, out _, out int lineInSource);
62
63 if (m_LineNumbers.ContainsKey(stepInfo.Position.Source) &&
64 lineInSource == m_LineNumbers[stepInfo.Position.Source])
65 {
66 return;
67 }
68
69 m_LineNumbers[stepInfo.Position.Source] = lineInSource;
70
71 if (!m_SeenFiles.Contains(stepInfo.Position.FileName ?? ""))
72 {
73 m_SeenFiles.Add(stepInfo.Position.FileName ?? "");
74 OnFileLoaded?.Invoke(stepInfo.Position.FileName ?? "");
75 }
76
77 OnStep?.Invoke(stepInfo);
78 }
79
84 private void LoadDebugger(string path)
85 {
87 }
88
92 public event Action<BadDebuggerStep>? OnStep;
93
97 public event Action<string>? OnFileLoaded;
98}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:28
BadRuntime Clone()
Clone this Runtime.
Definition BadRuntime.cs:96
BadRuntime UseApi(BadInteropApi api, bool replace=false)
Adds or Replaces a specified API.
BadRuntimeExecutionResult ExecuteFile(string file, IFileSystem? fileSystem=null)
Executes the specified script file.
Implements the Debugger API for the Scriptable Debugger.
readonly List< string > m_SeenFiles
The Files that are already seen by the Debugger.
readonly Dictionary< string, int > m_LineNumbers
The Line Numbers/Positions for the Debugger.
void Step(BadDebuggerStep stepInfo)
Gets called on every step when the Debugger is attached.
Action< string >? OnFileLoaded
Event that gets called when a new file is loaded.
readonly BadRuntime m_Runtime
The Debugger Execution Context Options.
void LoadDebugger(string path)
Loads the Debugger from the given File Path.
BadScriptDebugger(BadRuntime runtime)
Constructs a new BadScriptDebugger instance.
BadScriptDebugger(BadRuntime runtime, string debuggerPath)
Constructs a new BadScriptDebugger instance.
Action< BadDebuggerStep >? OnStep
Event that gets called on every debugger step.
The Debugger Settings that are used by the Scriptable Debugger.
static T Instance
Returns the Instance of the Settings Provider.
Defines the Debugging Interface.
Contains the scriptable debugger implementation for the BadScript2 Runtime.
Contains the debugging abstractions for the BadScript2 Runtime.
Definition BadDebugger.cs:7
Represents a Debugging Step.
readonly BadSourcePosition Position
The Source Position of the Step.
string[] GetLines(int top, int bottom, out int topInSource, out int lineInSource)
Returns a line excerpt of the Step.