BadScript 2
Loading...
Searching...
No Matches
BadImportExpression.cs
Go to the documentation of this file.
6
8
13{
17 public readonly string Name;
18
22 public readonly string Path;
23
30 public BadImportExpression(string name, string path, BadSourcePosition position) : base(false, position)
31 {
32 Name = name;
33 Path = path;
34 }
35
37 public override IEnumerable<BadExpression> GetDescendants()
38 {
39 yield break;
40 }
41
49 public static IEnumerable<BadObject> Import(BadExecutionContext ctx, string name, string path)
50 {
51 BadModuleImporter? importer = ctx.Scope.GetSingleton<BadModuleImporter>();
52 if (importer == null)
53 {
54 throw BadRuntimeException.Create(ctx.Scope, "Module Importer not found");
55 }
56
57 IEnumerable<BadObject> result = importer.Get(path);
59 foreach (BadObject o in result)
60 {
61 r = o;
62
63 yield return o;
64 }
65
66 r = r.Dereference();
67
68 yield return r;
69 if (ctx.Scope.HasLocal(name, ctx.Scope, false))
70 {
71 throw BadRuntimeException.Create(ctx.Scope, $"Variable '{name}' already defined in current scope.");
72 }
73
74 ctx.Scope.DefineVariable(name, r, ctx.Scope, new BadPropertyInfo(r.GetPrototype(), true));
75 }
76
78 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
79 {
80 return Import(context, Name, Path);
81 }
82}
Describes a specific position inside a source file.
Base Implementation for all Expressions used inside the Script.
A Import Expression that is used to import a module from a specified path.
override IEnumerable< BadExpression > GetDescendants()
static IEnumerable< BadObject > Import(BadExecutionContext ctx, string name, string path)
Imports a module from the specified path and assigns it to the specified name.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadImportExpression(string name, string path, BadSourcePosition position)
Creates a new Import Expression.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
The Class that manages the importing of modules.
IEnumerable< BadObject > Get(string path)
Imports a module from the specified path.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Stores Meta Information about a Property.
Contains Shared Data Structures and Functionality.
Contains the Error Objects for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.