forked from ZeraGmbH/Blockly.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Context.cs
70 lines (58 loc) · 1.83 KB
/
Context.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using BlocklyNet.Scripting.Engine;
namespace BlocklyNet.Core.Model;
/// <summary>
/// Script execution context.
/// </summary>
public class Context
{
/// <summary>
/// Script engine running.
/// </summary>
public IScriptSite Engine { get; private set; }
/// <summary>
/// Provide access to the dependency injection.
/// </summary>
public IServiceProvider ServiceProvider => Engine.ServiceProvider;
/// <summary>
/// Control cancel of a script.
/// </summary>
public CancellationToken Cancellation => Engine.Cancellation;
/// <summary>
/// Initialize a new context.
/// </summary>
/// <param name="engine">Script engine to use.</param>
public Context(IScriptSite engine)
{
Engine = engine;
}
/// <summary>
/// Initialize a new context.
/// </summary>
/// <param name="parent">Parent context to use.</param>
public Context(Context parent)
{
Parent = parent;
Engine = parent.Engine;
Functions = parent.Functions;
}
/// <summary>
/// The values of all variables.
/// </summary>
public IDictionary<string, object?> Variables { get; } = new Dictionary<string, object?>();
/// <summary>
/// All functions available in this context.
/// </summary>
public IDictionary<string, object> Functions { get; private set; } = new Dictionary<string, object>();
/// <summary>
/// How to leave loops.
/// </summary>
public EscapeMode EscapeMode { get; set; }
/// <summary>
/// Optional parent context - e.g. for the context of a currently exceuted function.
/// </summary>
public Context? Parent { get; private set; }
/// <summary>
/// In parallel mode the run script block will not evaluate but report itself.
/// </summary>
public int ParallelMode { get; set; }
}