BadScript 2
Loading...
Searching...
No Matches
BadInteropImportHandler.cs
Go to the documentation of this file.
6
8
10{
11 private readonly BadFunction m_GetFunction;
14 private readonly BadFunction m_HasFunction;
16
18 {
19 m_HandlerContext = ctx;
20 BadObject has = scriptHandler.GetProperty("Has").Dereference();
21 if (has is not BadFunction hasF)
22 {
23 throw new BadRuntimeException("Has function not found");
24 }
25
26 m_HasFunction = hasF;
27 BadObject get = scriptHandler.GetProperty("Get").Dereference();
28 if (get is not BadFunction getF)
29 {
30 throw new BadRuntimeException("Get function not found");
31 }
32
33 m_GetFunction = getF;
34 BadObject getHash = scriptHandler.GetProperty("GetHash").Dereference();
35 if (getHash is not BadFunction getHashF)
36 {
37 throw new BadRuntimeException("GetHash function not found");
38 }
39
40 m_GetHashFunction = getHashF;
41
42 BadObject isTransient = scriptHandler.GetProperty("IsTransient").Dereference();
43
44 if (isTransient is not BadFunction isTransientF)
45 {
46 throw new BadRuntimeException("IsTransient function not found");
47 }
48
49 m_IsTransientFunction = isTransientF;
50 }
51
52 private BadObject RunFunction(BadFunction func, params BadObject[] args)
53 {
54 IEnumerable<BadObject> e = func.Invoke(args, m_HandlerContext);
55 BadObject? result = BadObject.Null;
56 foreach (BadObject o in e)
57 {
58 result = o;
59 }
60
61
62 return result.Dereference();
63 }
64
65 public override bool IsTransient()
66 {
68 if (result is not IBadBoolean b)
69 {
70 throw new BadRuntimeException("IsTransient function did not return a boolean");
71 }
72
73 return b.Value;
74 }
75
76 public override bool Has(string path)
77 {
78 BadObject result = RunFunction(m_HasFunction, path);
79 if (result is not IBadBoolean b)
80 {
81 throw new BadRuntimeException("Has function did not return a boolean");
82 }
83
84 return b.Value;
85 }
86
87 public override string GetHash(string path)
88 {
90 if (result is not IBadString s)
91 {
92 throw new BadRuntimeException("GetHash function did not return a string");
93 }
94
95 return s.Value;
96 }
97
98 public override IEnumerable<BadObject> Get(string path)
99 {
100 BadObject? result = BadObject.Null;
102 {
103 result = o;
104
105 yield return o;
106 }
107
108
109 yield return result.Dereference();
110 }
111}
The Execution Context. Every execution of a script needs a context the script is running in....
static BadExecutionContext Create(BadInteropExtensionProvider provider)
Creates a new Execution Context with an empty scope.
Defines the shape of the import handler for the module importer.
override IEnumerable< BadObject > Get(string path)
BadObject RunFunction(BadFunction func, params BadObject[] args)
BadInteropImportHandler(BadExecutionContext ctx, BadObject scriptHandler)
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
virtual BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadObject.cs:129
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements a function that can be called from the script.
IEnumerable< BadObject > Invoke(BadObject[] args, BadExecutionContext caller)
Invokes the function with the specified arguments.
Implements the Interface for Native Boolean.
Definition IBadBoolean.cs:7
Implements the Interface for Native Strings.
Definition IBadString.cs:7
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains Runtime Function Objects.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10