BadScript 2
Loading...
Searching...
No Matches
BadScript2.BadRuntime Class Reference

Exposes the BadScript Runtime Functionality to Consumers. More...

Inheritance diagram for BadScript2.BadRuntime:

Public Member Functions

 BadRuntime (BadExecutionContextOptions options)
 Creates a new BadScript Runtime with the specified options.
 
 BadRuntime ()
 Creates a new BadScript Runtime with the default options.
 
void Dispose ()
 Disposes all Disposables.
 
BadRuntime Clone ()
 Clone this Runtime.
 
BadRuntime UseExecutor (Func< BadExecutionContext, IEnumerable< BadExpression >, BadObject > executor)
 Configures the Runtime to use the specified Executor.
 
BadRuntime UseLogMask (params BadLogMask[] mask)
 Configures the Runtime to use the specified log masks.
 
BadRuntime UseLogMask (params string[] mask)
 Configures the Runtime to use the specified log masks.
 
BadRuntime UseConsole (IBadConsole console)
 Configures the Runtime to use the specified console implementation.
 
BadRuntime UseLogWriter (BadLogWriter writer)
 Configures the Runtime to use the specified logwriter implementation.
 
BadRuntime UseConsoleLogWriter ()
 Configures the Runtime to use the default log writer implementation(log to console)
 
BadRuntime UseFileLogWriter (string path)
 Configures the Runtime to use the file log writer implementation.
 
BadRuntime LoadSettings (string settingsFile, IFileSystem? fileSystem=null)
 Loads the specified settings file.
 
BadRuntime UseCompilerApi ()
 Configures the Runtime to expose the CompilerAPI to the Scripts.
 
BadRuntime UseDebugger (IBadDebugger debugger)
 Configures the Runtime to use the specified Debugger.
 
BadExecutionContext CreateContext (string workingDirectory)
 Creates a new Context with the configured Options.
 
BadRuntimeExecutionResult Execute (IEnumerable< BadExpression > expressions, string workingDirectory)
 Executes the specified expressions.
 
BadRuntimeExecutionResult Execute (string source)
 Executes the specified script.
 
BadRuntimeExecutionResult Execute (string source, string file)
 Executes the specified script.
 
BadRuntimeExecutionResult ExecuteFile (string file, IFileSystem? fileSystem=null)
 Executes the specified script file.
 
BadRuntime UseLocalModules (IFileSystem? fs=null)
 Registers the Local Path Handler to the Module Importer.
 
BadRuntime ConfigureContextOptions (params Action< BadExecutionContextOptions >[] action)
 Adds the specified Option Configuration Actions.
 
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 UseExtension< T > ()
 Uses a specified Extension.
 
BadRuntime UseImportHandler (Func< BadExecutionContext, string, BadModuleImporter, BadImportHandler > f)
 Configures a Module Importer to use the specified Import Handler.
 
BadRuntime UseImportHandler (Func< BadExecutionContext, BadModuleImporter, BadImportHandler > f)
 Configures a Module Importer to use the specified Import Handler.
 
BadRuntime UseImportHandler (Func< BadModuleImporter, BadImportHandler > f)
 Configures a Module Importer to use the specified Import Handler.
 
BadRuntime UseImportHandler (Func< string, BadModuleImporter, BadImportHandler > f)
 Configures a Module Importer to use the specified Import Handler.
 
BadRuntime UseImportHandler (BadImportHandler handler)
 Configures a Module Importer to use the specified Import Handler.
 
BadRuntime ConfigureModuleImporter (Action< BadExecutionContext, string, BadModuleImporter > action)
 Configures the Module Importer.
 
BadRuntime ConfigureModuleImporter (Action< BadExecutionContext, BadModuleImporter > action)
 Configures the Module Importer.
 
BadRuntime ConfigureModuleImporter (Action< BadModuleImporter > action)
 Configures the Module Importer.
 
BadRuntime ConfigureModuleImporter (Action< string, BadModuleImporter > action)
 Configures the Module Importer.
 
BadRuntime UseSingleton< T > (T obj)
 Uses the specified Singleton Object.
 
BadRuntime ConfigureContext (params Action< BadExecutionContext >[] action)
 Adds the specified Context Configuration Actions.
 

Static Public Member Functions

static IEnumerable< BadExpressionParse (string source)
 Parses the specified source.
 
static IEnumerable< BadExpressionParse (string source, string file)
 Parses the specified source.
 
static IEnumerable< BadExpressionParseFile (string file, IFileSystem? fileSystem=null)
 Parses the specified script file.
 

Properties

BadModuleStore ModuleStore = new BadModuleStore() [get]
 
BadModuleImporterImporter [get, set]
 

Private Member Functions

BadExecutionContextOptions CreateOptions ()
 Creates and configures the Options for the Context.
 

Static Private Member Functions

static BadObject Executor (BadExecutionContext ctx, IEnumerable< BadExpression > exprs)
 The Default Executor Function.
 

Private Attributes

readonly List< Action< BadExecutionContext > > m_ConfigureContext = new List<Action<BadExecutionContext>>()
 Configuration Actions for the Context.
 
readonly List< Action< BadExecutionContext, string, BadModuleImporter > > m_ConfigureModuleImporter = new List<Action<BadExecutionContext, string, BadModuleImporter>>()
 
readonly List< Action< BadExecutionContextOptions > > m_ConfigureOptions
 Configuration Actions for the Options.
 
readonly List< IDisposable > m_Disposables = new List<IDisposable>()
 List of Disposables.
 
readonly BadExecutionContextOptions m_Options
 The Options for the Context.
 
Func< BadExecutionContext, IEnumerable< BadExpression >, BadObjectm_Executor = Executor
 The Executor Function used to Execute a list of Expressions.
 

Detailed Description

Exposes the BadScript Runtime Functionality to Consumers.

Definition at line 27 of file BadRuntime.cs.

Constructor & Destructor Documentation

◆ BadRuntime() [1/2]

BadScript2.BadRuntime.BadRuntime ( BadExecutionContextOptions  options)

Creates a new BadScript Runtime with the specified options.

Parameters
optionsThe Options to use

Definition at line 61 of file BadRuntime.cs.

62 {
63 m_Options = options;
64
66 {
68 }
69 }
readonly BadExecutionContextOptions m_Options
The Options for the Context.
Definition BadRuntime.cs:50
Public Api for the Settings System.
Helper class that can be used to automatically load a settings object from a file.
static void SetRootSettings(BadSettings settings)
Sets the Root Settings Object.
static bool HasRootSettings
Returns true if the root setting has been set.

◆ BadRuntime() [2/2]

BadScript2.BadRuntime.BadRuntime ( )

Creates a new BadScript Runtime with the default options.

Definition at line 74 of file BadRuntime.cs.

74: this(new BadExecutionContextOptions()) { }
Provides settings for creating a new BadExecutionContext

Member Function Documentation

◆ Clone()

BadRuntime BadScript2.BadRuntime.Clone ( )

Clone this Runtime.

Returns
Cloned Runtime

Definition at line 96 of file BadRuntime.cs.

97 {
99 .UseExecutor(m_Executor);
100
101 //Copy the configurators that are not part of the options
102 r.m_ConfigureModuleImporter.AddRange(m_ConfigureModuleImporter);
103 r.m_ConfigureContext.AddRange(m_ConfigureContext);
104
105 return r;
106 }
BadExecutionContextOptions CreateOptions()
Creates and configures the Options for the Context.
readonly List< Action< BadExecutionContext, string, BadModuleImporter > > m_ConfigureModuleImporter
Definition BadRuntime.cs:34
Func< BadExecutionContext, IEnumerable< BadExpression >, BadObject > m_Executor
The Executor Function used to Execute a list of Expressions.
Definition BadRuntime.cs:55
BadRuntime()
Creates a new BadScript Runtime with the default options.
Definition BadRuntime.cs:74
readonly List< Action< BadExecutionContext > > m_ConfigureContext
Configuration Actions for the Context.
Definition BadRuntime.cs:32

◆ ConfigureContext()

BadRuntime BadScript2.BadRuntime.ConfigureContext ( params Action< BadExecutionContext >[]  action)

Adds the specified Context Configuration Actions.

Parameters
actionThe Configuration Actions
Returns
This Runtime

Definition at line 568 of file BadRuntime.cs.

569 {
570 m_ConfigureContext.AddRange(action);
571
572 return this;
573 }

◆ ConfigureContextOptions()

BadRuntime BadScript2.BadRuntime.ConfigureContextOptions ( params Action< BadExecutionContextOptions >[]  action)

Adds the specified Option Configuration Actions.

Parameters
actionThe Configuration Actions
Returns
This Runtime

Definition at line 407 of file BadRuntime.cs.

408 {
409 m_ConfigureOptions.AddRange(action);
410
411 return this;
412 }
readonly List< Action< BadExecutionContextOptions > > m_ConfigureOptions
Configuration Actions for the Options.
Definition BadRuntime.cs:39

◆ ConfigureModuleImporter() [1/4]

BadRuntime BadScript2.BadRuntime.ConfigureModuleImporter ( Action< BadExecutionContext, BadModuleImporter action)

Configures the Module Importer.

Parameters
actionModule Importer Configuration Action
Returns
This Runtime

Definition at line 527 of file BadRuntime.cs.

528 {
529 return ConfigureModuleImporter((ctx, _, importer) => action(ctx, importer));
530 }
BadRuntime ConfigureModuleImporter(Action< BadExecutionContext, string, BadModuleImporter > action)
Configures the Module Importer.

◆ ConfigureModuleImporter() [2/4]

BadRuntime BadScript2.BadRuntime.ConfigureModuleImporter ( Action< BadExecutionContext, string, BadModuleImporter action)

Configures the Module Importer.

Parameters
actionModule Importer Configuration Action
Returns
This Runtime

Definition at line 515 of file BadRuntime.cs.

516 {
517 m_ConfigureModuleImporter.Add(action);
518
519 return this;
520 }

◆ ConfigureModuleImporter() [3/4]

BadRuntime BadScript2.BadRuntime.ConfigureModuleImporter ( Action< BadModuleImporter action)

Configures the Module Importer.

Parameters
actionModule Importer Configuration Action
Returns
This Runtime

Definition at line 537 of file BadRuntime.cs.

538 {
539 return ConfigureModuleImporter((_, _, importer) => action(importer));
540 }

◆ ConfigureModuleImporter() [4/4]

BadRuntime BadScript2.BadRuntime.ConfigureModuleImporter ( Action< string, BadModuleImporter action)

Configures the Module Importer.

Parameters
actionModule Importer Configuration Action
Returns
This Runtime

Definition at line 547 of file BadRuntime.cs.

548 {
549 return ConfigureModuleImporter((_, workingDir, importer) => action(workingDir, importer));
550 }

◆ CreateContext()

BadExecutionContext BadScript2.BadRuntime.CreateContext ( string  workingDirectory)

Creates a new Context with the configured Options.

Returns
The new Context

Definition at line 266 of file BadRuntime.cs.

267 {
269
270 foreach (Action<BadExecutionContext> config in m_ConfigureContext)
271 {
272 config(ctx);
273 }
274
275 ctx.Scope.AddSingleton(this);
276 BadModuleImporter importer;
277 if (Importer == null)
278 {
279 importer = Importer = new BadModuleImporter(ModuleStore);
280 }
281 else
282 {
283 importer = Importer = Importer.Clone();
284 }
285
286 foreach (Action<BadExecutionContext, string, BadModuleImporter> action in m_ConfigureModuleImporter)
287 {
288 action(ctx, workingDirectory, importer);
289 }
290
291 ctx.Scope.AddSingleton(importer);
292
293 return ctx;
294 }
BadModuleImporter? Importer
Definition BadRuntime.cs:77
BadModuleStore ModuleStore
Definition BadRuntime.cs:76
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
BadExecutionContext Build()
Builds a new BadExecutionContext with the options provided in this Options Instance.
The Class that manages the importing of modules.
BadModuleImporter Clone(bool onlyTransient=true)

◆ CreateOptions()

BadExecutionContextOptions BadScript2.BadRuntime.CreateOptions ( )
private

Creates and configures the Options for the Context.

Returns
The Options for the Context

Definition at line 250 of file BadRuntime.cs.

251 {
253
254 foreach (Action<BadExecutionContextOptions> config in m_ConfigureOptions)
255 {
256 config(opts);
257 }
258
259 return opts;
260 }
BadExecutionContextOptions Clone()
Clones this BadExecutionContextOptions instance.

◆ Dispose()

void BadScript2.BadRuntime.Dispose ( )

Disposes all Disposables.

Definition at line 84 of file BadRuntime.cs.

85 {
86 foreach (IDisposable disposable in m_Disposables)
87 {
88 disposable.Dispose();
89 }
90 }
readonly List< IDisposable > m_Disposables
List of Disposables.
Definition BadRuntime.cs:45

◆ Execute() [1/3]

BadRuntimeExecutionResult BadScript2.BadRuntime.Execute ( IEnumerable< BadExpression expressions,
string  workingDirectory 
)

Executes the specified expressions.

Parameters
expressionsThe Expressions to execute
Returns
The Result of the Execution

Definition at line 301 of file BadRuntime.cs.

302 {
303 BadExecutionContext ctx = CreateContext(workingDirectory);
304
305 BadObject? result = m_Executor(ctx, expressions);
306 BadObject exports = ctx.Scope.GetExports();
307
308 return new BadRuntimeExecutionResult(result, exports);
309 }
BadExecutionContext CreateContext(string workingDirectory)
Creates a new Context with the configured Options.
BadObject GetExports()
Returns the exported key value pairs of the scope.
Definition BadScope.cs:717
The Base Class for all BadScript Objects.
Definition BadObject.cs:14

◆ Execute() [2/3]

BadRuntimeExecutionResult BadScript2.BadRuntime.Execute ( string  source)

Executes the specified script.

Parameters
sourceThe Script Source to execute
Returns
The Result of the Execution

Definition at line 317 of file BadRuntime.cs.

318 {
320 }
BadRuntimeExecutionResult Execute(IEnumerable< BadExpression > expressions, string workingDirectory)
Executes the specified expressions.
static IEnumerable< BadExpression > Parse(string source)
Parses the specified source.
Public interface for the filesystem abstraction of the BadScript Engine.
static IFileSystem Instance
File System implementation.
string GetCurrentDirectory()
Returns the Current Directory.

◆ Execute() [3/3]

BadRuntimeExecutionResult BadScript2.BadRuntime.Execute ( string  source,
string  file 
)

Executes the specified script.

Parameters
sourceThe Script Source to execute
fileThe File Path of the Script
Returns
The Result of the Execution

Definition at line 328 of file BadRuntime.cs.

329 {
330 return Execute(Parse(source, file), Path.GetDirectoryName(BadFileSystem.Instance.GetFullPath(file)) ?? BadFileSystem.Instance.GetCurrentDirectory());
331 }
string GetFullPath(string path)
Returns the full path of the given path.

◆ ExecuteFile()

BadRuntimeExecutionResult BadScript2.BadRuntime.ExecuteFile ( string  file,
IFileSystem fileSystem = null 
)

Executes the specified script file.

Parameters
fileThe File Path of the Script
fileSystemThe (optional) Filesystem Instance to use
Returns
The Result of the Execution

Definition at line 339 of file BadRuntime.cs.

340 {
341 var fs = fileSystem ?? BadFileSystem.Instance;
342 return Execute(ParseFile(file, fs), fs.GetFullPath(Path.GetDirectoryName(fs.GetFullPath(file)) ?? fs.GetCurrentDirectory()));
343 }
static IEnumerable< BadExpression > ParseFile(string file, IFileSystem? fileSystem=null)
Parses the specified script file.

◆ Executor()

static BadObject BadScript2.BadRuntime.Executor ( BadExecutionContext  ctx,
IEnumerable< BadExpression exprs 
)
staticprivate

The Default Executor Function.

Parameters
ctxThe Context to use
exprsThe Expressions to execute
Returns
The Result of the Execution

Definition at line 126 of file BadRuntime.cs.

127 {
128 return ctx.ExecuteScript(exprs);
129 }
BadObject ExecuteScript(IEnumerable< BadExpression > expressions)
Executes an enumeration of expressions and returns the last value.

◆ LoadSettings()

BadRuntime BadScript2.BadRuntime.LoadSettings ( string  settingsFile,
IFileSystem fileSystem = null 
)

Loads the specified settings file.

Parameters
settingsFileThe path to the settings file
Returns
This Runtime

Definition at line 203 of file BadRuntime.cs.

204 {
205 BadLogger.Log("Loading Settings...", "Settings");
206 BadSettingsReader settingsReader = new BadSettingsReader(
208 fileSystem ?? BadFileSystem.Instance,
209 settingsFile
210 );
211
213 BadLogger.Log("Settings loaded!", "Settings");
214
215 return this;
216 }
Public facing interface for a logger.
Definition BadLogger.cs:7
static void Log(string message)
Writes a Log to the Message Handler.
Definition BadLogger.cs:26
static BadSettings RootSettings
Returns the Root Settings Object.
Reads a JSON file and returns the resulting BadSettings Object.
BadSettings ReadSettings()
Returns a new Instance of BadSettings with all source files loaded.

◆ Parse() [1/2]

static IEnumerable< BadExpression > BadScript2.BadRuntime.Parse ( string  source)
static

Parses the specified source.

Parameters
sourceThe Source to parse
Returns
The Parsed Expressions

Definition at line 350 of file BadRuntime.cs.

351 {
352 return Parse(source, "<memory>");
353 }

◆ Parse() [2/2]

static IEnumerable< BadExpression > BadScript2.BadRuntime.Parse ( string  source,
string  file 
)
static

Parses the specified source.

Parameters
sourceThe Source to parse
fileThe File Path of the Script
Returns
The Parsed Expressions

Definition at line 361 of file BadRuntime.cs.

362 {
363 BadSourceParser parser = BadSourceParser.Create(file, source);
364
365 IEnumerable<BadExpression> result = parser.Parse();
366
367 if (BadNativeOptimizationSettings.Instance.UseConstantFoldingOptimization)
368 {
369 result = BadConstantFoldingOptimizer.Optimize(result);
370 }
371
372 if (BadNativeOptimizationSettings.Instance.UseConstantSubstitutionOptimization)
373 {
375 }
376
377 return result;
378 }
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Contains the Implementation of the Constant Substitution Optimization This optimization replaces expr...
static IEnumerable< BadExpression > Optimize(BadConstantSubstitutionOptimizerScope scope, IEnumerable< BadExpression > expressions)
Substitutes all variables in the expressions with their constant value.
The Parser of the Language. It turns Source Code into an Expression Tree.
static BadSourceParser Create(string fileName, string source)
Creates a BadSourceParser Instance based on the source and filename provided.
static IEnumerable< BadExpression > Parse(string fileName, string source)
Parses a BadExpression from the Source Reader.
static T Instance
Returns the Instance of the Settings Provider.

◆ ParseFile()

static IEnumerable< BadExpression > BadScript2.BadRuntime.ParseFile ( string  file,
IFileSystem fileSystem = null 
)
static

Parses the specified script file.

Parameters
fileThe File Path of the Script
fileSystemThe (optional) Filesystem Instance to use
Returns
The Parsed Expressions

Definition at line 386 of file BadRuntime.cs.

387 {
388 var fs = fileSystem ?? BadFileSystem.Instance;
389 return Parse(fs.ReadAllText(file), file);
390 }

◆ UseApi()

BadRuntime BadScript2.BadRuntime.UseApi ( BadInteropApi  api,
bool  replace = false 
)

Adds or Replaces a specified API.

Parameters
apiThe API to add or replace
replaceIf the API should be replaced if it already exists
Returns
This Runtime

Definition at line 420 of file BadRuntime.cs.

421 {
422 if (replace)
423 {
424 return ConfigureContextOptions(opt => opt.AddOrReplaceApi(api));
425 }
426
427 return ConfigureContextOptions(opt => opt.AddApi(api));
428 }
BadRuntime ConfigureContextOptions(params Action< BadExecutionContextOptions >[] action)
Adds the specified Option Configuration Actions.

◆ UseApis()

BadRuntime BadScript2.BadRuntime.UseApis ( IEnumerable< BadInteropApi apis,
bool  replace = false 
)

Adds or Replaces a specified APIs.

Parameters
apiThe APIs to add or replace
replaceIf the APIs should be replaced if they already exist
Returns
This Runtime

Definition at line 437 of file BadRuntime.cs.

438 {
439 if (replace)
440 {
441 return ConfigureContextOptions(opt => opt.AddOrReplaceApis(apis));
442 }
443
444 return ConfigureContextOptions(opt => opt.AddApis(apis));
445 }

◆ UseCompilerApi()

BadRuntime BadScript2.BadRuntime.UseCompilerApi ( )

Configures the Runtime to expose the CompilerAPI to the Scripts.

Returns
This Runtime

Definition at line 222 of file BadRuntime.cs.

223 {
225
226 return this;
227 }
void AddApi(BadInteropApi api)
Adds a new Api to the context.

◆ UseConsole()

BadRuntime BadScript2.BadRuntime.UseConsole ( IBadConsole  console)

Configures the Runtime to use the specified console implementation.

Parameters
consoleThe Console to use
Returns
This Runtime

Definition at line 158 of file BadRuntime.cs.

159 {
160 BadConsole.SetConsole(console);
161
162 return this;
163 }
Wrapper class for the console abstraction.
Definition BadConsole.cs:12
static void SetConsole(IBadConsole console)
Sets the Current Console Implementation.
Definition BadConsole.cs:58

◆ UseConsoleLogWriter()

BadRuntime BadScript2.BadRuntime.UseConsoleLogWriter ( )

Configures the Runtime to use the default log writer implementation(log to console)

Returns
This Runtime

Definition at line 183 of file BadRuntime.cs.

184 {
185 return UseLogWriter(new BadConsoleLogWriter());
186 }
BadRuntime UseLogWriter(BadLogWriter writer)
Configures the Runtime to use the specified logwriter implementation.

◆ UseDebugger()

BadRuntime BadScript2.BadRuntime.UseDebugger ( IBadDebugger  debugger)

Configures the Runtime to use the specified Debugger.

Parameters
debuggerThe Debugger to use
Returns
This Runtime

Definition at line 234 of file BadRuntime.cs.

235 {
237 {
239 }
240
241 BadDebugger.Attach(debugger);
242
243 return this;
244 }
Public Debugger Interface.
static bool IsAttached
True if a debugger is attached.
static void Attach(IBadDebugger debugger)
Attaches a debugger to the system.
static void Detach()
Detaches the debugger from the system.

◆ UseExecutor()

BadRuntime BadScript2.BadRuntime.UseExecutor ( Func< BadExecutionContext, IEnumerable< BadExpression >, BadObject executor)

Configures the Runtime to use the specified Executor.

Parameters
executorThe Executor to use
Returns
This Runtime

Definition at line 113 of file BadRuntime.cs.

114 {
115 m_Executor = executor;
116
117 return this;
118 }

◆ UseExtension< T >()

BadRuntime BadScript2.BadRuntime.UseExtension< T > ( )

Uses a specified Extension.

Template Parameters
TThe Extension Type
Returns
This Runtime
Type Constraints
T :BadInteropExtension 
T :new() 

Definition at line 453 of file BadRuntime.cs.

453 : BadInteropExtension, new()
454 {
455 return ConfigureContextOptions(opts => opts.AddExtension<T>());
456 }
Public Extension API for the BS2 Runtime.

◆ UseFileLogWriter()

BadRuntime BadScript2.BadRuntime.UseFileLogWriter ( string  path)

Configures the Runtime to use the file log writer implementation.

Parameters
pathThe path to the log file
Returns
This Runtime

Definition at line 193 of file BadRuntime.cs.

194 {
195 return UseLogWriter(new BadFileLogWriter(path));
196 }
Implements a simple file writer for the log system.

◆ UseImportHandler() [1/5]

BadRuntime BadScript2.BadRuntime.UseImportHandler ( BadImportHandler  handler)

Configures a Module Importer to use the specified Import Handler.

Parameters
handlerThe Import Handler to use
Returns
This Runtime

Definition at line 504 of file BadRuntime.cs.

505 {
506 return ConfigureModuleImporter(importer => importer.AddHandler(handler));
507 }

◆ UseImportHandler() [2/5]

BadRuntime BadScript2.BadRuntime.UseImportHandler ( Func< BadExecutionContext, BadModuleImporter, BadImportHandler f)

Configures a Module Importer to use the specified Import Handler.

Parameters
fHandler Factory
Returns
This Runtime

Definition at line 474 of file BadRuntime.cs.

475 {
476 return ConfigureModuleImporter((ctx, importer) => importer.AddHandler(f(ctx, importer)));
477 }

◆ UseImportHandler() [3/5]

BadRuntime BadScript2.BadRuntime.UseImportHandler ( Func< BadExecutionContext, string, BadModuleImporter, BadImportHandler f)

Configures a Module Importer to use the specified Import Handler.

Parameters
fHandler Factory
Returns
This Runtime

Definition at line 464 of file BadRuntime.cs.

465 {
466 return ConfigureModuleImporter((ctx, workingDir, importer) => importer.AddHandler(f(ctx, workingDir, importer)));
467 }

◆ UseImportHandler() [4/5]

BadRuntime BadScript2.BadRuntime.UseImportHandler ( Func< BadModuleImporter, BadImportHandler f)

Configures a Module Importer to use the specified Import Handler.

Parameters
fHandler Factory
Returns
This Runtime

Definition at line 484 of file BadRuntime.cs.

485 {
486 return ConfigureModuleImporter(importer => importer.AddHandler(f(importer)));
487 }

◆ UseImportHandler() [5/5]

BadRuntime BadScript2.BadRuntime.UseImportHandler ( Func< string, BadModuleImporter, BadImportHandler f)

Configures a Module Importer to use the specified Import Handler.

Parameters
fHandler Factory
Returns
This Runtime

Definition at line 494 of file BadRuntime.cs.

495 {
496 return ConfigureModuleImporter((workingDir, importer) => importer.AddHandler(f(workingDir, importer)));
497 }

◆ UseLocalModules()

BadRuntime BadScript2.BadRuntime.UseLocalModules ( IFileSystem fs = null)

Registers the Local Path Handler to the Module Importer.

Returns
This Runtime

Definition at line 397 of file BadRuntime.cs.

398 {
399 return UseImportHandler((workingDir, _) => new BadLocalPathImportHandler(this, workingDir, fs ?? BadFileSystem.Instance));
400 }
BadRuntime UseImportHandler(Func< BadExecutionContext, string, BadModuleImporter, BadImportHandler > f)
Configures a Module Importer to use the specified Import Handler.

◆ UseLogMask() [1/2]

BadRuntime BadScript2.BadRuntime.UseLogMask ( params BadLogMask[]  mask)

Configures the Runtime to use the specified log masks.

Parameters
maskThe Log Masks to use
Returns
This Runtime

Definition at line 136 of file BadRuntime.cs.

137 {
138 BadLogWriterSettings.Instance.Mask = BadLogMask.GetMask(mask);
139
140 return this;
141 }
Implements a Mask for Log Messages.
Definition BadLogMask.cs:7
static BadLogMask GetMask(params BadLogMask[] masks)
Returns a combined mask of all masks provided.

◆ UseLogMask() [2/2]

BadRuntime BadScript2.BadRuntime.UseLogMask ( params string[]  mask)

Configures the Runtime to use the specified log masks.

Parameters
maskThe Log Masks to use
Returns
This Runtime

Definition at line 148 of file BadRuntime.cs.

149 {
150 return UseLogMask(mask.Select(x => (BadLogMask)x).ToArray());
151 }
BadRuntime UseLogMask(params BadLogMask[] mask)
Configures the Runtime to use the specified log masks.

◆ UseLogWriter()

BadRuntime BadScript2.BadRuntime.UseLogWriter ( BadLogWriter  writer)

Configures the Runtime to use the specified logwriter implementation.

Parameters
writerThe LogWriter to use
Returns
This Runtime

Definition at line 170 of file BadRuntime.cs.

171 {
172 writer.Register();
173 m_Disposables.Add(writer);
174
175 return this;
176 }
void Register()
Registers the Log Writer to the Log System.

◆ UseSingleton< T >()

BadRuntime BadScript2.BadRuntime.UseSingleton< T > ( obj)

Uses the specified Singleton Object.

Parameters
objThe Object to use
Template Parameters
TType of the Object
Returns
This Runtime
Type Constraints
T :class 

Definition at line 558 of file BadRuntime.cs.

558 : class
559 {
560 return ConfigureContext(ctx => ctx.Scope.AddSingleton(obj));
561 }
BadRuntime ConfigureContext(params Action< BadExecutionContext >[] action)
Adds the specified Context Configuration Actions.

Member Data Documentation

◆ m_ConfigureContext

readonly List<Action<BadExecutionContext> > BadScript2.BadRuntime.m_ConfigureContext = new List<Action<BadExecutionContext>>()
private

Configuration Actions for the Context.

Definition at line 32 of file BadRuntime.cs.

◆ m_ConfigureModuleImporter

readonly List<Action<BadExecutionContext, string, BadModuleImporter> > BadScript2.BadRuntime.m_ConfigureModuleImporter = new List<Action<BadExecutionContext, string, BadModuleImporter>>()
private

Definition at line 34 of file BadRuntime.cs.

◆ m_ConfigureOptions

readonly List<Action<BadExecutionContextOptions> > BadScript2.BadRuntime.m_ConfigureOptions
private
Initial value:
=
new List<Action<BadExecutionContextOptions>>()

Configuration Actions for the Options.

Definition at line 39 of file BadRuntime.cs.

◆ m_Disposables

readonly List<IDisposable> BadScript2.BadRuntime.m_Disposables = new List<IDisposable>()
private

List of Disposables.

Definition at line 45 of file BadRuntime.cs.

◆ m_Executor

Func<BadExecutionContext, IEnumerable<BadExpression>, BadObject> BadScript2.BadRuntime.m_Executor = Executor
private

The Executor Function used to Execute a list of Expressions.

Definition at line 55 of file BadRuntime.cs.

◆ m_Options

readonly BadExecutionContextOptions BadScript2.BadRuntime.m_Options
private

The Options for the Context.

Definition at line 50 of file BadRuntime.cs.

Property Documentation

◆ Importer

BadModuleImporter? BadScript2.BadRuntime.Importer
getsetprivate

Definition at line 77 of file BadRuntime.cs.

77{ get; set; }

◆ ModuleStore

BadModuleStore BadScript2.BadRuntime.ModuleStore = new BadModuleStore()
getprivate

Definition at line 76 of file BadRuntime.cs.

76{ get; } = new BadModuleStore();
Is the store for all loaded modules.

The documentation for this class was generated from the following file: