BadScript 2
Loading...
Searching...
No Matches
BadLocalPathImportHandler.cs
Go to the documentation of this file.
1using BadScript2.IO;
5
7
12{
16 private readonly IFileSystem m_FileSystem;
17
21 private readonly BadRuntime m_Runtime;
22
26 private readonly string m_WorkingDirectory;
27
33 public BadLocalPathImportHandler(BadRuntime runtime, string workingDirectory, IFileSystem mFileSystem)
34 {
35 m_Runtime = runtime;
36 m_WorkingDirectory = workingDirectory;
37 m_FileSystem = mFileSystem;
38 }
39
45 private string GetPath(string path)
46 {
47 string p = m_FileSystem.GetFullPath(Path.Combine(m_WorkingDirectory, path));
48
49 if (!p.EndsWith("." + BadRuntimeSettings.Instance.FileExtension))
50 {
51 p += "." + BadRuntimeSettings.Instance.FileExtension;
52 }
53
54 return p;
55 }
56
57 public override bool IsTransient()
58 {
59 return false;
60 }
61
63 public override bool Has(string path)
64 {
65 string fullPath = GetPath(path);
66
67 return m_FileSystem.IsFile(fullPath);
68 }
69
71 public override string GetHash(string path)
72 {
73 string fullPath = GetPath(path);
74
75 return "file://" + fullPath;
76 }
77
79 public override IEnumerable<BadObject> Get(string path)
80 {
81 string fullPath = GetPath(path);
82
83 IEnumerable<BadExpression> parsed = BadRuntime.ParseFile(fullPath);
84
85 BadExecutionContext ctx = m_Runtime.CreateContext(Path.GetDirectoryName(fullPath) ?? "/");
86
87
88 foreach (BadObject o in ctx.Execute(parsed))
89 {
90 yield return o;
91 }
92
93 yield return ctx.Scope.GetExports();
94 }
95}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:28
BadExecutionContext CreateContext(string workingDirectory)
Creates a new Context with the configured Options.
static IEnumerable< BadExpression > ParseFile(string file, IFileSystem? fileSystem=null)
Parses the specified script file.
The Execution Context. Every execution of a script needs a context the script is running in....
Defines the shape of the import handler for the module importer.
string GetPath(string path)
Returns the full path for the specified path.
BadLocalPathImportHandler(BadRuntime runtime, string workingDirectory, IFileSystem mFileSystem)
Creates a new BadLocalPathImportHandler instance.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static T Instance
Returns the Instance of the Settings Provider.
Defines the interface for a file system.
Definition IFileSystem.cs:7
bool IsFile(string path)
Returns true if the given path is a file.
string GetFullPath(string path)
Returns the full path of the given path.
Contains IO Implementation for the BadScript2 Runtime.
Contains the Expressions for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains Runtime Settings Objects.