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
42 public BadExecutionContextOptions(IEnumerable<BadInteropApi> apis,
43 IEnumerable<BadInteropExtension> extensions) : this(apis)
44 {
45 m_Extensions.AddRange(extensions);
46 }
47
52
56 public IEnumerable<BadInteropApi> Apis => m_Apis;
57
62 public void AddExtension<T>() where T : BadInteropExtension, new()
63 {
64 T t = new T();
65 AddExtension(t);
66 }
67
72 public void AddExtensions(params BadInteropExtension[] extensions)
73 {
74 foreach (BadInteropExtension extension in extensions)
75 {
76 AddExtension(extension);
77 }
78 }
79
84 public void AddExtension(BadInteropExtension extension)
85 {
86 m_Extensions.Add(extension);
87 }
88
93 public void AddApi(BadInteropApi api)
94 {
95 m_Apis.Add(api);
96 }
97
102 public void AddOrReplaceApis(IEnumerable<BadInteropApi> apis)
103 {
104 foreach (BadInteropApi api in apis)
105 {
106 AddOrReplaceApi(api);
107 }
108 }
109
115 {
116 int index = m_Apis.FindIndex(x => x.Name == api.Name);
117
118 if (index == -1)
119 {
120 AddApi(api);
121 }
122 else
123 {
124 m_Apis[index] = api;
125 }
126 }
127
132 public void AddApis(IEnumerable<BadInteropApi> apis)
133 {
134 m_Apis.AddRange(apis);
135 }
136
142 {
144
145 foreach (BadInteropApi api in m_Apis)
146 {
147 BadTable table;
148
149 if (ctx.Scope.HasLocal(api.Name, ctx.Scope) &&
150 ctx.Scope.GetVariable(api.Name)
151 .Dereference(null) is BadTable t)
152 {
153 table = t;
154 }
155 else
156 {
157 table = new BadTable();
158 ctx.Scope.DefineVariable(api.Name, table);
159 }
160
161 api.Load(ctx, table);
162 }
163
165 {
166 ctx.Scope.DefineVariable(type.Name, type);
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.