BadScript 2
Loading...
Searching...
No Matches
BadCommonInterop.cs
Go to the documentation of this file.
11
16
20public static class BadCommonInterop
21{
25 private static readonly BadInteropApi[] s_CommonApis =
26 {
28 new BadRuntimeApi(),
29 new BadMathApi(),
31 new BadXmlApi(),
32 };
33
37 public static IEnumerable<BadInteropApi> Apis => s_CommonApis;
38
39
46 public static BadRuntime UseStartupArguments(this BadRuntime runtime, IEnumerable<string> args)
47 {
48 BadRuntimeApi.StartupArguments = args;
49
50 return runtime;
51 }
52
59 private static BadObject ExecuteTask(BadExecutionContext ctx, IEnumerable<BadExpression> exprs)
60 {
61 BadTask task = new BadTask(
62 new BadInteropRunnable(ctx.Execute(exprs.ToArray()).GetEnumerator()),
63 "Main"
64 );
66 task,
67 true
68 );
69
70
72 {
74 }
75
76 return task.Runnable.GetReturn();
77 }
78
85 public static BadRuntime UseCommonInterop(this BadRuntime runtime, bool useAsync = true)
86 {
87 if (useAsync)
88 {
90 {
92 }
93
94 runtime
97 .UseSingleton(BadTaskRunner.Instance);
98 }
99
101 {
103 }
104
105 return runtime.UseCommonExtensions(useAsync)
106 .UseApis(Apis, true);
107 }
108
115 public static BadRuntime UseConsoleApi(this BadRuntime runtime, IBadConsole? console = null)
116 {
117 if (console != null)
118 {
119 return runtime.UseApi(new BadConsoleApi(console), true);
120 }
121
122 return runtime.UseApi(new BadConsoleApi(BadConsole.GetConsole()), true);
123 }
124
125 public static BadRuntime UseCommonExtensions(this BadRuntime runtime, bool useAsync = true)
126 {
127 if (useAsync)
128 {
129 runtime.UseExtension<BadTaskExtensions>();
130 }
131
132 return runtime
133 .UseExtension<BadObjectExtension>()
134 .UseExtension<BadStringExtension>()
135 .UseExtension<BadNumberExtension>()
136 .UseExtension<BadTableExtension>()
137 .UseExtension<BadScopeExtension>()
138 .UseExtension<BadArrayExtension>()
139 .UseExtension<BadFunctionExtension>()
140 .UseExtension<BadTypeSystemExtension>();
141 }
142}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:28
BadRuntime UseApi(BadInteropApi api, bool replace=false)
Adds or Replaces a specified API.
BadRuntime UseApis(IEnumerable< BadInteropApi > apis, bool replace=false)
Adds or Replaces a specified APIs.
BadRuntime UseExecutor(Func< BadExecutionContext, IEnumerable< BadExpression >, BadObject > executor)
Configures the Runtime to use the specified Executor.
Wrapper class for the console abstraction.
Definition BadConsole.cs:12
static IBadConsole GetConsole()
Returns the Current Console Implementation.
Definition BadConsole.cs:49
Implements the Common Interop Wrapper.
static BadRuntime UseConsoleApi(this BadRuntime runtime, IBadConsole? console=null)
Configures the Runtime to use the Console API.
static BadRuntime UseCommonInterop(this BadRuntime runtime, bool useAsync=true)
Configures the Runtime to use the Common Interop Extensions.
static BadObject ExecuteTask(BadExecutionContext ctx, IEnumerable< BadExpression > exprs)
The Default Executor for asynchronous execution.
static BadRuntime UseCommonExtensions(this BadRuntime runtime, bool useAsync=true)
static BadRuntime UseStartupArguments(this BadRuntime runtime, IEnumerable< string > args)
Configures the Runtime to use the specified startup arguments.
static IEnumerable< BadInteropApi > Apis
All Common Interop Apis.
static readonly BadInteropApi[] s_CommonApis
All Common Interop Apis.
Implements a Runnable that can return a value.
BadObject GetReturn()
Gets the Return Value.
Implements a Task Object.
Definition BadTask.cs:17
static readonly BadClassPrototype Prototype
The BadTask Prototype.
Definition BadTask.cs:21
BadRunnable Runnable
Runnable of the Task.
Definition BadTask.cs:102
void RunStep()
Runs a single step of the Task Runner.
void AddTask(BadTask task, bool runImmediately=false)
Adds a Task to the Task Runner.
static readonly BadTaskRunner Instance
The Task Runner Instance.
bool IsIdle
Is true if there are no tasks to run.
static readonly BadClassPrototype Prototype
The Version Class Prototype.
Definition BadVersion.cs:22
The Execution Context. Every execution of a script needs a context the script is running in....
IEnumerable< BadObject > Execute(IEnumerable< BadExpression > expressions)
Executes an enumeration of expressions.
Implements an Interop API for the BS2 Language.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Helper Class that Builds a Native Class from a Prototype.
static void AddNative(BadClassPrototype native)
Adds a native Type.
static IEnumerable< BadClassPrototype > NativeTypes
Enumeration of all Native Class Prototypes.
Interface that abstracts the console.
Contains a Console Abstraction Layer to be able to Simulate Console Input/Output over the Network.
Definition BadConsole.cs:6
Contains Common Interop APIs for the BadScript2 Runtime.
Contains Common Interop Extensions for the BadScript2 Runtime.
Contains task/async Extensions and Integrations for the BadScript2 Runtime.
Contains Versioning Extensions and APIs for the BadScript2 Runtime.
Definition BadVersion.cs:11
Contains Common Interop Extensions and APIs for the BadScript2 Runtime.
Contains the Expressions for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.