BadScript 2
Loading...
Searching...
No Matches
BadExecutionContextOptions.cs
Go to the documentation of this file.
4
5namespace BadScript2.Runtime;
6
11{
15 private readonly List<BadInteropApi> m_Apis = new List<BadInteropApi>();
16
20 private readonly List<BadInteropExtension> m_Extensions = new List<BadInteropExtension>();
21
26 public BadExecutionContextOptions(IEnumerable<BadInteropApi> apis)
27 {
28 m_Apis.AddRange(apis);
29 }
30
35 public BadExecutionContextOptions(params BadInteropApi[] apis) : this((IEnumerable<BadInteropApi>)apis) { }
36
43 IEnumerable<BadInteropApi> apis,
44 IEnumerable<BadInteropExtension> extensions) : this(apis)
45 {
46 m_Extensions.AddRange(extensions);
47 }
48
53
57 public IEnumerable<BadInteropApi> Apis => m_Apis;
58
63 public void AddExtension<T>() where T : BadInteropExtension, new()
64 {
65 T t = new T();
66 AddExtension(t);
67 }
68
73 public void AddExtensions(params BadInteropExtension[] extensions)
74 {
75 foreach (BadInteropExtension extension in extensions)
76 {
77 AddExtension(extension);
78 }
79 }
80
85 public void AddExtension(BadInteropExtension extension)
86 {
87 m_Extensions.Add(extension);
88 }
89
94 public void AddApi(BadInteropApi api)
95 {
96 m_Apis.Add(api);
97 }
98
103 public void AddOrReplaceApis(IEnumerable<BadInteropApi> apis)
104 {
105 foreach (BadInteropApi api in apis)
106 {
107 AddOrReplaceApi(api);
108 }
109 }
110
116 {
117 int index = m_Apis.FindIndex(x => x.Name == api.Name);
118
119 if (index == -1)
120 {
121 AddApi(api);
122 }
123 else
124 {
125 m_Apis[index] = api;
126 }
127 }
128
133 public void AddApis(IEnumerable<BadInteropApi> apis)
134 {
135 m_Apis.AddRange(apis);
136 }
137
143 {
145
146 foreach (BadInteropApi api in m_Apis)
147 {
148 BadTable table;
149
150 if (ctx.Scope.HasLocal(api.Name, ctx.Scope) && ctx.Scope.GetVariable(api.Name).Dereference() is BadTable t)
151 {
152 table = t;
153 }
154 else
155 {
156 table = new BadTable();
157 ctx.Scope.DefineVariable(api.Name, table);
158 }
159
160 api.Load(ctx, table);
161 }
162
164 {
165 ctx.Scope.DefineVariable(type.Name, type);
166 }
167
168
169 return ctx;
170 }
171
180}
The Execution Context. Every execution of a script needs a context the script is running in....
static BadExecutionContext Create(BadInteropExtensionProvider provider)
Creates a new Execution Context with an empty scope.
Provides settings for creating a new BadExecutionContext
BadExecutionContextOptions(IEnumerable< BadInteropApi > apis, IEnumerable< BadInteropExtension > extensions)
Creates a new instance of the BadExecutionContextOptions class.
void AddOrReplaceApis(IEnumerable< BadInteropApi > apis)
Adds or Replaces apis in the context.
BadExecutionContextOptions(IEnumerable< BadInteropApi > apis)
Creates a new instance of the BadExecutionContextOptions class.
void AddOrReplaceApi(BadInteropApi api)
Adds or Replaces an api in the context.
BadExecutionContext Build()
Builds a new BadExecutionContext with the options provided in this Options Instance.
void AddExtensions(params BadInteropExtension[] extensions)
Adds new Extensions to the context.
void AddApi(BadInteropApi api)
Adds a new Api to the context.
static BadExecutionContextOptions Empty
An Empty BadExecutionContextOptions instance.
BadExecutionContextOptions(params BadInteropApi[] apis)
Creates a new instance of the BadExecutionContextOptions class.
void AddApis(IEnumerable< BadInteropApi > apis)
Adds Apis to the context.
readonly List< BadInteropApi > m_Apis
List of APIs that are loaded in the context.
IEnumerable< BadInteropApi > Apis
List of APIs that are loaded in the context.
void AddExtension< T >()
Adds a new Extension to the context.
BadExecutionContextOptions Clone()
Clones this BadExecutionContextOptions instance.
void AddExtension(BadInteropExtension extension)
Adds a new Extension to the context.
readonly List< BadInteropExtension > m_Extensions
List of Extensions that are loaded in the context.
Implements an Interop API for the BS2 Language.
void Load(BadExecutionContext ctx, BadTable table)
Loads the API into the given Table.
Public Extension API for the BS2 Runtime.
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
Implements a Class Prototype for the BadScript Language.
Helper Class that Builds a Native Class from a Prototype.
static IEnumerable< BadClassPrototype > NativeTypes
Enumeration of all Native Class Prototypes.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.