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.
 
BadRuntime UseCulture (CultureInfo culture)
 
BadRuntime UseCulture (string culture)
 

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

CultureInfo Culture = CultureInfo.InvariantCulture [get, private set]
 
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
 
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 29 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 64 of file BadRuntime.cs.

65 {
66 m_Options = options;
67
69 {
71 }
72 }
readonly BadExecutionContextOptions m_Options
The Options for the Context.
Definition BadRuntime.cs:53
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 77 of file BadRuntime.cs.

77: 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 106 of file BadRuntime.cs.

107 {
109 .UseExecutor(m_Executor);
110
111 //Copy the configurators that are not part of the options
112 r.m_ConfigureModuleImporter.AddRange(m_ConfigureModuleImporter);
113 r.m_ConfigureContext.AddRange(m_ConfigureContext);
114
115 return r;
116 }
BadExecutionContextOptions CreateOptions()
Creates and configures the Options for the Context.
readonly List< Action< BadExecutionContext, string, BadModuleImporter > > m_ConfigureModuleImporter
Definition BadRuntime.cs:36
Func< BadExecutionContext, IEnumerable< BadExpression >, BadObject > m_Executor
The Executor Function used to Execute a list of Expressions.
Definition BadRuntime.cs:58
BadRuntime()
Creates a new BadScript Runtime with the default options.
Definition BadRuntime.cs:77
readonly List< Action< BadExecutionContext > > m_ConfigureContext
Configuration Actions for the Context.
Definition BadRuntime.cs:34

◆ 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 592 of file BadRuntime.cs.

593 {
594 m_ConfigureContext.AddRange(action);
595
596 return this;
597 }

◆ 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 430 of file BadRuntime.cs.

431 {
432 m_ConfigureOptions.AddRange(action);
433
434 return this;
435 }
readonly List< Action< BadExecutionContextOptions > > m_ConfigureOptions
Configuration Actions for the Options.
Definition BadRuntime.cs:42

◆ 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 551 of file BadRuntime.cs.

552 {
553 return ConfigureModuleImporter((ctx, _, importer) => action(ctx, importer));
554 }
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 539 of file BadRuntime.cs.

540 {
541 m_ConfigureModuleImporter.Add(action);
542
543 return this;
544 }

◆ 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 561 of file BadRuntime.cs.

562 {
563 return ConfigureModuleImporter((_, _, importer) => action(importer));
564 }

◆ 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 571 of file BadRuntime.cs.

572 {
573 return ConfigureModuleImporter((_, workingDir, importer) => action(workingDir, importer));
574 }

◆ CreateContext()

BadExecutionContext BadScript2.BadRuntime.CreateContext ( string  workingDirectory)

Creates a new Context with the configured Options.

Returns
The new Context

Definition at line 278 of file BadRuntime.cs.

279 {
281 .Build();
282
283 foreach (Action<BadExecutionContext> config in m_ConfigureContext)
284 {
285 config(ctx);
286 }
287
288 ctx.Scope.AddSingleton(this);
289 BadModuleImporter importer;
290
291 if (Importer == null)
292 {
293 importer = Importer = new BadModuleImporter(ModuleStore);
294 }
295 else
296 {
297 importer = Importer = Importer.Clone();
298 }
299
300 foreach (Action<BadExecutionContext, string, BadModuleImporter> action in m_ConfigureModuleImporter)
301 {
302 action(ctx, workingDirectory, importer);
303 }
304
305 ctx.Scope.AddSingleton(importer);
306
307 return ctx;
308 }
BadModuleImporter? Importer
Definition BadRuntime.cs:83
BadModuleStore ModuleStore
Definition BadRuntime.cs:81
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 262 of file BadRuntime.cs.

263 {
265
266 foreach (Action<BadExecutionContextOptions> config in m_ConfigureOptions)
267 {
268 config(opts);
269 }
270
271 return opts;
272 }
BadExecutionContextOptions Clone()
Clones this BadExecutionContextOptions instance.

◆ Dispose()

void BadScript2.BadRuntime.Dispose ( )

Disposes all Disposables.

Definition at line 92 of file BadRuntime.cs.

93 {
94 foreach (IDisposable disposable in m_Disposables)
95 {
96 disposable.Dispose();
97 }
98 }
readonly List< IDisposable > m_Disposables
List of Disposables.
Definition BadRuntime.cs:48

◆ 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 315 of file BadRuntime.cs.

316 {
317 BadExecutionContext ctx = CreateContext(workingDirectory);
318
319 BadObject? result = m_Executor(ctx, expressions);
320 BadObject exports = ctx.Scope.GetExports();
321
322 return new BadRuntimeExecutionResult(result, exports);
323 }
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:522
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 331 of file BadRuntime.cs.

332 {
334 }
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 342 of file BadRuntime.cs.

343 {
344 return Execute(Parse(source, file),
345 Path.GetDirectoryName(BadFileSystem.Instance.GetFullPath(file)) ??
347 );
348 }
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 356 of file BadRuntime.cs.

357 {
358 IFileSystem? fs = fileSystem ?? BadFileSystem.Instance;
359
360 return Execute(ParseFile(file, fs),
361 fs.GetFullPath(Path.GetDirectoryName(fs.GetFullPath(file)) ?? fs.GetCurrentDirectory())
362 );
363 }
static IEnumerable< BadExpression > ParseFile(string file, IFileSystem? fileSystem=null)
Parses the specified script file.
Defines the interface for a file system.
Definition IFileSystem.cs:7

◆ 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 136 of file BadRuntime.cs.

137 {
138 return ctx.ExecuteScript(exprs);
139 }
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 215 of file BadRuntime.cs.

216 {
217 BadLogger.Log("Loading Settings...", "Settings");
218
220 fileSystem ?? BadFileSystem.Instance,
221 settingsFile
222 );
223
225 BadLogger.Log("Settings loaded!", "Settings");
226
227 return this;
228 }
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 370 of file BadRuntime.cs.

371 {
372 return Parse(source, "<memory>");
373 }

◆ 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 381 of file BadRuntime.cs.

382 {
383 BadSourceParser parser = BadSourceParser.Create(file, source);
384
385 IEnumerable<BadExpression> result = parser.Parse();
386
387 if (BadNativeOptimizationSettings.Instance.UseConstantFoldingOptimization)
388 {
389 result = BadConstantFoldingOptimizer.Optimize(result);
390 }
391
392 if (BadNativeOptimizationSettings.Instance.UseConstantSubstitutionOptimization)
393 {
395 }
396
397 return result;
398 }
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 406 of file BadRuntime.cs.

407 {
408 IFileSystem? fs = fileSystem ?? BadFileSystem.Instance;
409
410 return Parse(fs.ReadAllText(file), file);
411 }

◆ 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 443 of file BadRuntime.cs.

444 {
445 if (replace)
446 {
447 return ConfigureContextOptions(opt => opt.AddOrReplaceApi(api));
448 }
449
450 return ConfigureContextOptions(opt => opt.AddApi(api));
451 }
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 460 of file BadRuntime.cs.

461 {
462 if (replace)
463 {
464 return ConfigureContextOptions(opt => opt.AddOrReplaceApis(apis));
465 }
466
467 return ConfigureContextOptions(opt => opt.AddApis(apis));
468 }

◆ UseCompilerApi()

BadRuntime BadScript2.BadRuntime.UseCompilerApi ( )

Configures the Runtime to expose the CompilerAPI to the Scripts.

Returns
This Runtime

Definition at line 234 of file BadRuntime.cs.

235 {
237
238 return this;
239 }
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 170 of file BadRuntime.cs.

171 {
172 BadConsole.SetConsole(console);
173
174 return this;
175 }
Wrapper class for the console abstraction.
Definition BadConsole.cs:12
static void SetConsole(IBadConsole console)
Sets the Current Console Implementation.
Definition BadConsole.cs:60

◆ UseConsoleLogWriter()

BadRuntime BadScript2.BadRuntime.UseConsoleLogWriter ( )

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

Returns
This Runtime

Definition at line 195 of file BadRuntime.cs.

196 {
197 return UseLogWriter(new BadConsoleLogWriter());
198 }
BadRuntime UseLogWriter(BadLogWriter writer)
Configures the Runtime to use the specified logwriter implementation.

◆ UseCulture() [1/2]

BadRuntime BadScript2.BadRuntime.UseCulture ( CultureInfo  culture)

Definition at line 599 of file BadRuntime.cs.

600 {
601 Culture = culture;
602
603 return this;
604 }
CultureInfo Culture
Definition BadRuntime.cs:79

◆ UseCulture() [2/2]

BadRuntime BadScript2.BadRuntime.UseCulture ( string  culture)

Definition at line 606 of file BadRuntime.cs.

607 {
608 return UseCulture(new CultureInfo(culture));
609 }
BadRuntime UseCulture(CultureInfo culture)

◆ 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 246 of file BadRuntime.cs.

247 {
249 {
251 }
252
253 BadDebugger.Attach(debugger);
254
255 return this;
256 }
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 123 of file BadRuntime.cs.

124 {
125 m_Executor = executor;
126
127 return this;
128 }

◆ 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 476 of file BadRuntime.cs.

476 : BadInteropExtension, new()
477 {
478 return ConfigureContextOptions(opts => opts.AddExtension<T>());
479 }
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 205 of file BadRuntime.cs.

206 {
207 return UseLogWriter(new BadFileLogWriter(path));
208 }
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 528 of file BadRuntime.cs.

529 {
530 return ConfigureModuleImporter(importer => importer.AddHandler(handler));
531 }

◆ 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 498 of file BadRuntime.cs.

499 {
500 return ConfigureModuleImporter((ctx, importer) => importer.AddHandler(f(ctx, importer)));
501 }

◆ 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 487 of file BadRuntime.cs.

488 {
489 return ConfigureModuleImporter((ctx, workingDir, importer) => importer.AddHandler(f(ctx, workingDir, importer))
490 );
491 }

◆ 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 508 of file BadRuntime.cs.

509 {
510 return ConfigureModuleImporter(importer => importer.AddHandler(f(importer)));
511 }

◆ 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 518 of file BadRuntime.cs.

519 {
520 return ConfigureModuleImporter((workingDir, importer) => importer.AddHandler(f(workingDir, importer)));
521 }

◆ UseLocalModules()

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

Registers the Local Path Handler to the Module Importer.

Returns
This Runtime

Definition at line 418 of file BadRuntime.cs.

419 {
420 return UseImportHandler((workingDir, _) =>
421 new BadLocalPathImportHandler(this, workingDir, fs ?? BadFileSystem.Instance)
422 );
423 }
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 146 of file BadRuntime.cs.

147 {
148 BadLogWriterSettings.Instance.Mask = BadLogMask.GetMask(mask);
149
150 return this;
151 }
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 158 of file BadRuntime.cs.

159 {
160 return UseLogMask(mask.Select(x => (BadLogMask)x)
161 .ToArray()
162 );
163 }
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 182 of file BadRuntime.cs.

183 {
184 writer.Register();
185 m_Disposables.Add(writer);
186
187 return this;
188 }
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 582 of file BadRuntime.cs.

582 : class
583 {
584 return ConfigureContext(ctx => ctx.Scope.AddSingleton(obj));
585 }
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 34 of file BadRuntime.cs.

◆ m_ConfigureModuleImporter

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

Definition at line 36 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 42 of file BadRuntime.cs.

◆ m_Disposables

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

List of Disposables.

Definition at line 48 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 58 of file BadRuntime.cs.

◆ m_Options

readonly BadExecutionContextOptions BadScript2.BadRuntime.m_Options
private

The Options for the Context.

Definition at line 53 of file BadRuntime.cs.

Property Documentation

◆ Culture

CultureInfo BadScript2.BadRuntime.Culture = CultureInfo.InvariantCulture
getprivate set

Definition at line 79 of file BadRuntime.cs.

79{ get; private set; } = CultureInfo.InvariantCulture;

◆ Importer

BadModuleImporter? BadScript2.BadRuntime.Importer
getsetprivate

Definition at line 83 of file BadRuntime.cs.

83{ get; set; }

◆ ModuleStore

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

Definition at line 81 of file BadRuntime.cs.

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

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