BadScript 2
Loading...
Searching...
No Matches
BadMemberInfo.cs
Go to the documentation of this file.
7
8namespace BadScript2.Runtime;
9
11{
14 (c, a) => throw BadRuntimeException.Create(c.Scope,
15 "MemberInfo is a read only object"
16 ),
17 null
18 );
19
20 private readonly Lazy<BadObjectReference> m_GetAttributesReference;
21 private readonly Lazy<BadObjectReference> m_GetValueReference;
22 private readonly Lazy<BadObjectReference> m_IsReadonlyReference;
23 private readonly Lazy<BadObjectReference> m_MemberTypeReference;
24 private readonly string m_Name;
25
26 private readonly Lazy<BadObjectReference> m_NameReference;
27 private readonly BadScope m_Scope;
28 private readonly Lazy<BadObjectReference> m_SetValueReference;
29
30 public BadMemberInfo(string name, BadScope scope)
31 {
32 m_Name = name;
33 m_Scope = scope;
34 m_NameReference = new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.Name", (p) => m_Name));
35
37 new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.GetAttributes",
38 (p) => new BadInteropFunction("GetAttributes",
40 false,
42 )
43 )
44 );
45
46 m_GetValueReference = new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.GetValue",
47 (p) => new BadInteropFunction("GetValue",
49 false,
51 )
52 )
53 );
54
55 m_SetValueReference = new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.SetValue",
56 (p) => new BadInteropFunction("SetValue",
58 false,
60 new BadFunctionParameter("value",
61 false,
62 false,
63 false,
64 null,
66 ),
67 new BadFunctionParameter("noChangeEvent",
68 true,
69 true,
70 false,
71 null,
73 )
74 )
75 )
76 );
77
79 new Lazy<BadObjectReference>(() =>
80 BadObjectReference.Make("MemberInfo.IsReadonly",
83 )
84 );
85
86 m_MemberTypeReference = new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.MemberType",
88 .Type ??
90 )
91 );
92 }
93
95
97 {
98 if (m_Scope.Attributes.TryGetValue(m_Name, out BadObject[]? attributes))
99 {
100 return new BadArray(attributes.ToList());
101 }
102
103 return new BadArray();
104 }
105
107 {
109 .Dereference(null);
110 }
111
113 {
114 if (args.Length == 1)
115 {
117 .Set(args[0], null);
118 }
119 else if (args.Length == 2)
120 {
121 if (args[1] is not IBadBoolean noEvents)
122 {
123 throw new BadRuntimeException("Second Argument must be a boolean");
124 }
125
127 .Set(args[0], null, null, noEvents.Value);
128 }
129
130 return Null;
131 }
132
133 public override bool HasProperty(string propName, BadScope? caller = null)
134 {
135 switch (propName)
136 {
137 case "Name":
138 case "GetAttributes":
139 case "GetValue":
140 case "SetValue":
141 case "IsReadonly":
142 case "MemberType":
143 return true;
144 default:
145 return base.HasProperty(propName, caller);
146 }
147 }
148
149 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
150 {
151 switch (propName)
152 {
153 case "Name":
154 return m_NameReference.Value;
155 case "GetAttributes":
156 return m_GetAttributesReference.Value;
157 case "GetValue":
158 return m_GetValueReference.Value;
159 case "SetValue":
160 return m_SetValueReference.Value;
161 case "IsReadonly":
162 return m_IsReadonlyReference.Value;
163 case "MemberType":
164 return m_MemberTypeReference.Value;
165 default:
166 return base.GetProperty(propName, caller);
167 }
168 }
169
170
172 {
173 return s_Prototype;
174 }
175
176 public override string ToSafeString(List<BadObject> done)
177 {
178 return "MemberInfo: " + m_Name;
179 }
180}
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
BadObject SetValue(BadExecutionContext ctx, BadObject[] args)
static BadClassPrototype Prototype
readonly Lazy< BadObjectReference > m_GetValueReference
readonly Lazy< BadObjectReference > m_MemberTypeReference
BadObject GetValue(BadExecutionContext ctx, BadObject[] args)
override BadClassPrototype GetPrototype()
BadMemberInfo(string name, BadScope scope)
readonly Lazy< BadObjectReference > m_IsReadonlyReference
override bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
readonly Lazy< BadObjectReference > m_NameReference
override string ToSafeString(List< BadObject > done)
readonly Lazy< BadObjectReference > m_GetAttributesReference
BadObject GetAttributes(BadExecutionContext ctx, BadObject[] args)
readonly Lazy< BadObjectReference > m_SetValueReference
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
static readonly BadNativeClassPrototype< BadMemberInfo > s_Prototype
Implements the Scope for the Script Engine.
Definition BadScope.cs:16
BadObjectReference GetVariable(string name, BadScope caller)
Returns the variable reference of the specified variable.
Definition BadScope.cs:879
IReadOnlyDictionary< string, BadObject[]> Attributes
Definition BadScope.cs:126
BadPropertyInfo GetVariableInfo(string name)
Returns the variable info of the specified variable.
Definition BadScope.cs:808
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
Interop Function taking an array of arguments.
Implements a Dynamic List/Array for the BadScript Language.
Definition BadArray.cs:17
static BadClassPrototype Prototype
The Prototype for the BadScript Array.
Definition BadArray.cs:40
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:141
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the base functionality for a BadScript Reference.
static BadObjectReference Make(string refText, Func< BadSourcePosition?, BadObject > getter, Action< BadObject, BadSourcePosition?, BadPropertyInfo?>? setter=null, Action< BadSourcePosition?>? delete=null)
Creates a new Reference Object.
void Set(BadObject obj, BadSourcePosition? position, BadPropertyInfo? info=null, bool noChangeEvent=false)
Sets the Referenced Object to a new Value.
bool IsReadOnly
Indicates if this property is read only.
BadClassPrototype? Type
The (optional) Type used for typechecking if a value gets assigned to this property.
The Any Prototype, Base type for all types.
static readonly BadAnyPrototype Instance
The Instance of the BadAnyPrototype.
Implements a Class Prototype for the BadScript Language.
Helper Class that Builds a Native Class from a Prototype.
static BadClassPrototype GetNative(string name)
Returns a Native Class Prototype for the given Native Type.
Implements the Interface for Native Boolean.
Definition IBadBoolean.cs:7
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Function Classes 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
Contains the Runtime Implementation.