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, BadSourcePosition? position)
50 {
51 BadModuleImporter? importer = ctx.Scope.GetSingleton<BadModuleImporter>();
52
53 if (importer == null)
54 {
55 throw BadRuntimeException.Create(ctx.Scope, "Module Importer not found");
56 }
57
58 IEnumerable<BadObject> result = importer.Get(path);
60
61 foreach (BadObject o in result)
62 {
63 r = o;
64
65 yield return o;
66 }
67
68 r = r.Dereference(position);
69
70 yield return r;
71
72 if (ctx.Scope.HasLocal(name, ctx.Scope, false))
73 {
74 throw BadRuntimeException.Create(ctx.Scope, $"Variable '{name}' already defined in current scope.");
75 }
76
77 ctx.Scope.DefineVariable(name, r, ctx.Scope, new BadPropertyInfo(r.GetPrototype(), true));
78 }
79
81 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
82 {
83 return Import(context, Name, Path, Position);
84 }
85}
Describes a specific position inside a source file.
Base Implementation for all Expressions used inside the Script.
BadSourcePosition Position
The source Position of the Expression.
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, BadSourcePosition? position)
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.