BadScript 2
Loading...
Searching...
No Matches
BadScope.cs
Go to the documentation of this file.
9
10namespace BadScript2.Runtime;
11
12public abstract class BadMemberChangeEvent : BadObject
13{
14 private readonly BadObject m_Instance;
15 private readonly BadMemberInfo m_Member;
16 private readonly BadObject m_OldValue;
17 private readonly BadObject m_NewValue;
18
19 protected BadMemberChangeEvent(BadObject mInstance, BadMemberInfo mMember, BadObject mOldValue, BadObject mNewValue)
20 {
21 m_Instance = mInstance;
22 m_Member = mMember;
23 m_OldValue = mOldValue;
24 m_NewValue = mNewValue;
25 }
26
27 public override bool HasProperty(string propName, BadScope? caller = null)
28 {
29 switch (propName)
30 {
31 case "Instance":
32 case "Member":
33 case "OldValue":
34 case "NewValue":
35 return true;
36 default:
37 return base.HasProperty(propName, caller);
38 }
39 }
40
41 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
42 {
43 switch (propName)
44 {
45 case "Instance":
46 return BadObjectReference.Make("MemberChangeEvent.Instance", () => m_Instance);
47 case "Member":
48 return BadObjectReference.Make("MemberChangeEvent.Member", () => m_Member);
49 case "OldValue":
50 return BadObjectReference.Make("MemberChangeEvent.OldValue", () => m_OldValue);
51 case "NewValue":
52 return BadObjectReference.Make("MemberChangeEvent.NewValue", () => m_NewValue);
53 default:
54 return base.GetProperty(propName, caller);
55 }
56 }
57 public override string ToSafeString(List<BadObject> done)
58 {
59 return $"{GetType().Name}: " + m_Member.ToSafeString(done);
60 }
61}
62
64{
65 public bool Cancel { get; private set; }
67
68
73
74 public override bool HasProperty(string propName, BadScope? caller = null)
75 {
76 if(propName == "Cancel")
77 {
78 return true;
79 }
80 return base.HasProperty(propName, caller);
81 }
82
83 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
84 {
85 if (propName == "Cancel")
86 {
87 return m_CancelReference;
88 }
89
90 return base.GetProperty(propName, caller);
91 }
92
93 public BadMemberChangingEvent(BadObject mInstance, BadMemberInfo mMember, BadObject mOldValue, BadObject mNewValue) : base(mInstance, mMember, mOldValue, mNewValue)
94 {
95 m_CancelReference = BadObjectReference.Make("MemberChangingEvent.Cancel", () => new BadInteropFunction("Cancel", (ctx, args) =>
96 {
97 Cancel = true;
98 return Null;
99 }, false, BadAnyPrototype.Instance));
100 }
101}
102
104{
109
110 public BadMemberChangedEvent(BadObject mInstance, BadMemberInfo mMember, BadObject mOldValue, BadObject mNewValue) : base(mInstance, mMember, mOldValue, mNewValue)
111 {
112 }
113}
114
116 {
117 private readonly string m_Name;
118 private readonly BadScope m_Scope;
121 "MemberInfo",
122 (c, a) => throw BadRuntimeException.Create(c.Scope, "MemberInfo is a read only object")
123 );
124
126
133
134 public BadMemberInfo(string name, BadScope scope)
135 {
136 m_Name = name;
137 m_Scope = scope;
138 m_NameReference = BadObjectReference.Make("MemberInfo.Name", () => m_Name);
139 m_GetAttributesReference = BadObjectReference.Make("MemberInfo.GetAttributes",
140 () => new BadInteropFunction("GetAttributes", GetAttributes, false, BadArray.Prototype));
141 m_GetValueReference = BadObjectReference.Make("MemberInfo.GetValue",
142 () => new BadInteropFunction("GetValue", GetValue, false, BadAnyPrototype.Instance));
143 m_SetValueReference = BadObjectReference.Make("MemberInfo.SetValue",
144 () => new BadInteropFunction("SetValue", SetValue, false, BadAnyPrototype.Instance,
145 new BadFunctionParameter("value", false, false, false, null, BadAnyPrototype.Instance),
146 new BadFunctionParameter("noChangeEvent", true, true, false, null, BadNativeClassBuilder.GetNative("bool"))));
148 BadObjectReference.Make("MemberInfo.IsReadonly", () => m_Scope.GetVariableInfo(m_Name).IsReadOnly);
149 m_MemberTypeReference = BadObjectReference.Make("MemberInfo.MemberType",
151 }
152
154 {
155 if(m_Scope.Attributes.TryGetValue(m_Name, out var attributes))
156 {
157 return new BadArray(attributes.ToList());
158 }
159
160 return new BadArray();
161 }
162
164 {
165 return m_Scope.GetVariable(m_Name).Dereference();
166 }
167
169 {
170 if(args.Length == 1)
171 {
172 m_Scope.GetVariable(m_Name, ctx.Scope).Set(args[0]);
173 }
174 else if(args.Length == 2)
175 {
176 if (args[1] is not IBadBoolean noEvents)
177 {
178 throw new BadRuntimeException("Second Argument must be a boolean");
179 }
180
181 m_Scope.GetVariable(m_Name, ctx.Scope).Set(args[0], null, noEvents.Value);
182 }
183 return Null;
184 }
185
186 public override bool HasProperty(string propName, BadScope? caller = null)
187 {
188 switch (propName)
189 {
190 case "Name":
191 case "GetAttributes":
192 case "GetValue":
193 case "SetValue":
194 case "IsReadonly":
195 case "MemberType":
196 return true;
197 default:
198 return base.HasProperty(propName, caller);
199 }
200 }
201
202 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
203 {
204 switch (propName)
205 {
206 case "Name":
207 return m_NameReference;
208 case "GetAttributes":
210 case "GetValue":
211 return m_GetValueReference;
212 case "SetValue":
213 return m_SetValueReference;
214 case "IsReadonly":
216 case "MemberType":
218 default:
219 return base.GetProperty(propName, caller);
220 }
221 }
222
223
225 {
226 return s_Prototype;
227 }
228
229 public override string ToSafeString(List<BadObject> done)
230 {
231 return "MemberInfo: " + m_Name;
232 }
233 }
237public class BadScope : BadObject, IDisposable
238{
242 private readonly List<Action> m_Finalizers = new List<Action>();
243
248
252 private readonly List<string> m_RegisteredApis = new List<string>();
253
257 private readonly BadTable m_ScopeVariables = new BadTable();
258
259 private readonly Dictionary<string, BadObject[]> m_Attributes = new Dictionary<string, BadObject[]>();
260
261 public IReadOnlyDictionary<string, BadObject[]> Attributes => m_Attributes;
262
264 {
265 return new BadArray(
266 m_ScopeVariables.InnerTable.Keys.Select(x => (BadObject)new BadMemberInfo(x, this)).ToList());
267 }
268
272 private readonly Dictionary<Type, object> m_SingletonCache = new Dictionary<Type, object>();
273
277 private readonly bool m_UseVisibility;
278
283
288
289 private bool m_IsDisposed;
290
298 public BadScope(
299 string name,
301 BadScope? caller = null,
302 BadScopeFlags flags = BadScopeFlags.RootScope)
303 {
304 Name = name;
305 Flags = flags;
306 m_Caller = caller;
307 m_Provider = provider;
309 m_ScopeVariables.OnChangedProperty += OnChanged;
310 }
311
320 public BadScope(
321 string name,
323 BadTable locals,
324 BadScope? caller = null,
325 BadScopeFlags flags = BadScopeFlags.RootScope)
326 {
327 Name = name;
328 Flags = flags;
329 m_Caller = caller;
330 m_ScopeVariables = locals;
331 m_Provider = provider;
333 m_ScopeVariables.OnChangedProperty += OnChanged;
334 }
335
344 private BadScope(
345 BadScope parent,
346 BadScope? caller,
347 string name,
348 BadScopeFlags flags = BadScopeFlags.RootScope,
349 bool useVisibility = false) : this(
350 name,
351 parent.Provider,
352 caller,
353 ClearCaptures(parent.Flags) | flags
354 )
355 {
356 m_UseVisibility = useVisibility;
357 Parent = parent;
358 }
359
363 public IReadOnlyCollection<string> RegisteredApis => Parent?.RegisteredApis ?? m_RegisteredApis;
364
368 public BadInteropExtensionProvider Provider => Parent != null ? Parent.Provider : m_Provider;
369
373 public BadClass? ClassObject { get; internal set; }
374
378 public BadFunction? FunctionObject { get; internal set; }
379
380
384 public BadScope? Parent { get; }
385
389 public string Name { get; }
390
394 public BadScopeFlags Flags { get; private set; }
395
399 private bool CountInStackTrace => (Flags & BadScopeFlags.CaptureReturn) != 0;
400
404 public bool IsBreak { get; private set; }
405
409 public bool IsContinue { get; private set; }
410
414 public BadObject? ReturnValue { get; private set; }
415
416
421 "Scope",
422 (c, args) =>
423 {
424 switch (args.Length)
425 {
426 case 1:
427 {
428 if (args[0] is not IBadString name)
429 {
430 throw new BadRuntimeException("Expected Name in Scope Constructor");
431 }
432
433 return CreateScope(c, name.Value);
434 }
435 case 2:
436 {
437 if (args[0] is not IBadString name)
438 {
439 throw new BadRuntimeException("Expected Name in Scope Constructor");
440 }
441
442 if (args[1] is not BadTable locals)
443 {
444 throw new BadRuntimeException("Expected Locals Table in Scope Constructor");
445 }
446
447 return CreateScope(c, name.Value, locals);
448 }
449 default:
450 throw new BadRuntimeException("Expected 1 or 2 Arguments in Scope Constructor");
451 }
452 }
453 );
454
458 public void Dispose()
459 {
460 if (m_IsDisposed)
461 {
462 return;
463 }
464
465 m_IsDisposed = true;
466 foreach (Action finalizer in m_Finalizers)
467 {
468 finalizer();
469 }
470
471 m_Finalizers.Clear();
472 }
473
478 internal void SetRegisteredApi(string api)
479 {
480 if (Parent != null)
481 {
482 Parent.SetRegisteredApi(api);
483
484 return;
485 }
486
487 if (!m_RegisteredApis.Contains(api))
488 {
489 m_RegisteredApis.Add(api);
490 }
491 }
492
498 public void AddFinalizer(Action finalizer)
499 {
500 if (m_IsDisposed)
501 {
502 throw BadRuntimeException.Create(this, "Scope is already disposed");
503 }
504
505 m_Finalizers.Add(finalizer);
506 }
507
512 public void SetCaller(BadScope? caller)
513 {
514 m_Caller = caller;
515 }
516
522 {
523 return Parent?.GetRootScope() ?? this;
524 }
525
532 public void AddSingleton<T>(T instance) where T : class
533 {
534 if (instance == null)
535 {
536 throw new BadRuntimeException("Cannot add null as singleton");
537 }
538
539 m_SingletonCache.Add(typeof(T), instance);
540 }
541
547 public T? GetSingleton<T>()
548 {
549 if (Parent != null)
550 {
551 return Parent.GetSingleton<T>();
552 }
553
554 if (m_SingletonCache.TryGetValue(typeof(T), out object? value))
555 {
556 return (T)value;
557 }
558
559 return default;
560 }
561
569 public T GetSingleton<T>(bool createNew) where T : new()
570 {
571 if (Parent != null)
572 {
573 return Parent.GetSingleton<T>(createNew);
574 }
575
576 if (m_SingletonCache.ContainsKey(typeof(T)))
577 {
578 return (T)m_SingletonCache[typeof(T)];
579 }
580
581 if (!createNew)
582 {
583 throw new Exception("Singleton not found");
584 }
585
586 T v = new T();
587 m_SingletonCache[typeof(T)] = v;
588
589 return v;
590 }
591
597 {
598 return Prototype;
599 }
600
608 private static BadScope CreateScope(BadExecutionContext ctx, string name, BadTable? locals = null)
609 {
610 BadScope s = locals != null ? new BadScope(name, ctx.Scope.Provider, locals) : new BadScope(name, ctx.Scope.Provider);
611
612 foreach (KeyValuePair<Type, object> kvp in ctx.Scope.GetRootScope().m_SingletonCache)
613 {
614 s.m_SingletonCache.Add(kvp.Key, kvp.Value);
615 }
616
617 return s;
618 }
619
624 public void SetFlags(BadScopeFlags flags)
625 {
626 Flags = flags;
627 }
628
633 public string GetStackTrace()
634 {
635 return GetStackTrace(this);
636 }
637
643 private static string GetStackTrace(BadScope scope)
644 {
645 BadScope? current = scope;
646 List<BadScope> stack = new List<BadScope>();
647
648 while (current != null)
649 {
650 if (current.CountInStackTrace)
651 {
652 stack.Add(current);
653 }
654
655 current = current.m_Caller ?? current.Parent;
656 }
657
658 return string.Join("\n", stack.Select(s => s.Name));
659 }
660
667 {
668 return flags &
669 ~(BadScopeFlags.CaptureReturn |
670 BadScopeFlags.CaptureBreak |
671 BadScopeFlags.CaptureContinue |
672 BadScopeFlags.CaptureThrow);
673 }
674
679 public void SetBreak()
680 {
681 if ((Flags & BadScopeFlags.AllowBreak) == 0)
682 {
683 throw new BadRuntimeException("Break not allowed in this scope");
684 }
685
686 IsBreak = true;
687
688 if ((Flags & BadScopeFlags.CaptureBreak) == 0)
689 {
690 Parent?.SetBreak();
691 }
692 }
693
698 public void SetContinue()
699 {
700 if ((Flags & BadScopeFlags.AllowContinue) == 0)
701 {
702 throw new BadRuntimeException("Continue not allowed in this scope");
703 }
704
705 IsContinue = true;
706
707 if ((Flags & BadScopeFlags.CaptureContinue) == 0)
708 {
709 Parent?.SetContinue();
710 }
711 }
712
718 {
719 return m_Exports ?? Null;
720 }
721
722 public void SetExports(BadExecutionContext ctx, BadObject exports)
723 {
724 if (m_Exports != null)
725 {
726 throw BadRuntimeException.Create(ctx.Scope, "Exports are already set");
727 }
728
729 m_Exports = exports;
730 }
731
737 public void AddExport(string key, BadObject value)
738 {
739 if (Parent != null)
740 {
741 Parent.AddExport(key, value);
742 }
743 else
744 {
745 if (m_Exports == null)
746 {
747 m_Exports = new BadTable();
748 }
749
750 m_Exports.SetProperty(key, value);
751 }
752 }
753
759 public void SetReturnValue(BadObject? value)
760 {
761 if ((Flags & BadScopeFlags.AllowReturn) == 0)
762 {
763 throw new BadRuntimeException("Return not allowed in this scope");
764 }
765
766 ReturnValue = value;
767
768 if ((Flags & BadScopeFlags.CaptureReturn) == 0)
769 {
770 Parent?.SetReturnValue(value);
771 }
772 }
773
779 {
780 return m_ScopeVariables;
781 }
782
783
793 string name,
794 BadScope? caller,
795 bool? useVisibility,
796 BadScopeFlags flags = BadScopeFlags.RootScope)
797 {
798 BadScope sc = new BadScope(this, caller, name, flags, useVisibility ?? m_UseVisibility)
799 {
800 ClassObject = ClassObject,
801 FunctionObject = FunctionObject,
802 };
803
804 return sc;
805 }
806 internal void OnChanged(string name, BadObject oldValue, BadObject newValue)
807 {
808 if (ClassObject == null)
809 {
810 return;
811 }
812 if (m_Attributes.TryGetValue(name, out var attributes))
813 {
814 var member = new BadMemberInfo(name, this);
815 foreach (BadClass attribute in attributes.OfType<BadClass>())
816 {
818 {
819 var invoke = (BadFunction)attribute.GetProperty("OnChanged").Dereference();
820 var eventObj = new BadMemberChangedEvent(ClassObject!, member, oldValue, newValue);
821 foreach (BadObject o in invoke.Invoke(new BadObject[] { eventObj }, new BadExecutionContext(this)))
822 {
823 //Execute
824 }
825 }
826 }
827 }
828 }
829 internal bool OnChange(string name, BadObject oldValue, BadObject newValue)
830 {
831 if (ClassObject == null)
832 {
833 return false;
834 }
835 if (m_Attributes.TryGetValue(name, out var attributes))
836 {
837 var member = new BadMemberInfo(name, this);
838 foreach (BadClass attribute in attributes.OfType<BadClass>())
839 {
841 {
842 var invoke = (BadFunction)attribute.GetProperty("OnChange").Dereference();
843 var eventObj = new BadMemberChangingEvent(ClassObject!, member, oldValue, newValue);
844 var obj = BadObject.Null;
845 foreach (BadObject o in invoke.Invoke(new BadObject[] { eventObj }, new BadExecutionContext(this)))
846 {
847 //Execute
848 obj = o;
849 }
850
851 if (eventObj.Cancel)
852 {
853 return true;
854 }
855 }
856 }
857 }
858
859 return false;
860 }
861 internal IEnumerable<BadObject> InitializeAttributes()
862 {
863 if (ClassObject == null)
864 {
865 throw new BadRuntimeException("Scope is not a class scope");
866 }
867 foreach (var kvp in m_Attributes)
868 {
869 var member = new BadMemberInfo(kvp.Key, this);
870 foreach (BadClass attribute in kvp.Value.OfType<BadClass>())
871 {
873 {
874 var invoke = (BadFunction)attribute.GetProperty("Initialize").Dereference();
875 foreach (BadObject o in invoke.Invoke(new BadObject[] { ClassObject!, member }, new BadExecutionContext(this)))
876 {
877 //Execute
878 yield return o;
879 }
880 }
881 }
882 }
883 }
884
885 public void DefineProperty(string name, BadClassPrototype type, BadExpression getAccessor, BadExpression? setAccessor, BadExecutionContext caller, BadObject[] attributes)
886 {
887 if (HasLocal(name, caller.Scope, false))
888 {
889 throw new BadRuntimeException($"Property {name} is already defined");
890 }
891 Action<BadObject, BadPropertyInfo?>? setter = null;
892 if (setAccessor != null)
893 {
894 setter = (value, pi) =>
895 {
896 BadExecutionContext? setCtx = new BadExecutionContext(caller.Scope.CreateChild($"set {name}", caller.Scope, null));
897 setCtx.Scope.DefineVariable("value", value, setCtx.Scope, new BadPropertyInfo(BadAnyPrototype.Instance, true));
898 foreach (BadObject o in setCtx.Execute(setAccessor))
899 {
900 //Execute
901 }
902 };
903 }
904 m_ScopeVariables.PropertyInfos.Add(name, new BadPropertyInfo(type, setter == null));
905 m_ScopeVariables.InnerTable.Add(name, BadObjectReference.Make($"property {name}",
906 () =>
907 {
908 BadExecutionContext? getCtx = new BadExecutionContext(caller.Scope.CreateChild($"get {name}", caller.Scope, null));
909 BadObject? get = Null;
910 foreach (BadObject o in getCtx.Execute(getAccessor))
911 {
912 get = o;
913 }
914 return get.Dereference();
915 },
916 setter));
917
918 m_Attributes[name] = attributes;
919 }
920
929 public void DefineVariable(string name, BadObject value, BadScope? caller = null, BadPropertyInfo? info = null, BadObject[]? attributes = null)
930 {
931 if (HasLocal(name, caller ?? this, false))
932 {
933 throw new BadRuntimeException($"Variable {name} is already defined");
934 }
935
936 m_Attributes[name] = attributes ?? [];
937 m_ScopeVariables.GetProperty(name, false, caller ?? this).Set(value, info, true);
938 }
939
947 {
948 if (HasLocal(name, this))
949 {
950 return m_ScopeVariables.GetPropertyInfo(name);
951 }
952
953 if (Parent == null)
954 {
955 throw new BadRuntimeException($"Variable '{name}' is not defined");
956 }
957
958 return Parent!.GetVariableInfo(name);
959 }
960
966 public static BadPropertyVisibility GetPropertyVisibility(string propName)
967 {
968 char first = propName[0];
969 char second = propName.Length > 1 ? propName[1] : '\0';
970
971 return second switch
972 {
973 '_' => first == '_' ? BadPropertyVisibility.Private : BadPropertyVisibility.Public,
974 _ => first == '_' ? BadPropertyVisibility.Protected : BadPropertyVisibility.Public,
975 };
976 }
977
983 public bool IsVisibleParentOf(BadScope scope)
984 {
985 if (scope == this)
986 {
987 return true;
988 }
989
990 BadScope? current = scope.Parent;
991
992 while (current != null)
993 {
994 if (!current.m_UseVisibility)
995 {
996 return false;
997 }
998
999 if (current == this)
1000 {
1001 return true;
1002 }
1003
1004
1005 current = current.Parent;
1006 }
1007
1008 return false;
1009 }
1010
1018 public BadObjectReference GetVariable(string name, BadScope caller)
1019 {
1020 if (m_UseVisibility)
1021 {
1022 BadPropertyVisibility vis = IsVisibleParentOf(caller) ? BadPropertyVisibility.All : BadPropertyVisibility.Public;
1023
1024 if ((GetPropertyVisibility(name) & vis) == 0)
1025 {
1026 throw BadRuntimeException.Create(caller, $"Variable '{name}' is not visible to {caller}");
1027 }
1028 }
1029
1030 if (HasLocal(name, caller))
1031 {
1032 return m_ScopeVariables.GetProperty(name, caller);
1033 }
1034
1035 if (Parent == null)
1036 {
1037 throw BadRuntimeException.Create(caller, $"Variable '{name}' is not defined");
1038 }
1039
1040 return Parent!.GetVariable(name, caller);
1041 }
1042
1050 {
1051 return GetVariable(name, this);
1052 }
1053
1061 public bool HasLocal(string name, BadScope caller, bool useExtensions = true)
1062 {
1063 return !useExtensions ? m_ScopeVariables.InnerTable.ContainsKey(name) : m_ScopeVariables.HasProperty(name, caller);
1064 }
1065
1072 public bool HasVariable(string name, BadScope caller)
1073 {
1074 return HasLocal(name, caller) || Parent != null && Parent.HasVariable(name, caller);
1075 }
1076
1077
1079 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
1080 {
1081 return HasVariable(propName, caller ?? this) ? GetVariable(propName, caller ?? this) : base.GetProperty(propName, caller);
1082 }
1083
1085 public override bool HasProperty(string propName, BadScope? caller = null)
1086 {
1087 return HasVariable(propName, caller ?? this) || base.HasProperty(propName, caller);
1088 }
1089
1090
1092 public override string ToSafeString(List<BadObject> done)
1093 {
1094 done.Add(this);
1095
1096 return m_ScopeVariables.ToSafeString(done);
1097 }
1098}
Base Implementation for all Expressions used inside the Script.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
override string ToSafeString(List< BadObject > done)
Definition BadScope.cs:57
readonly BadMemberInfo m_Member
Definition BadScope.cs:15
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadScope.cs:41
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...
Definition BadScope.cs:27
BadMemberChangeEvent(BadObject mInstance, BadMemberInfo mMember, BadObject mOldValue, BadObject mNewValue)
Definition BadScope.cs:19
BadMemberChangedEvent(BadObject mInstance, BadMemberInfo mMember, BadObject mOldValue, BadObject mNewValue)
Definition BadScope.cs:110
override BadClassPrototype GetPrototype()
Definition BadScope.cs:105
override BadClassPrototype GetPrototype()
Definition BadScope.cs:69
readonly BadObjectReference m_CancelReference
Definition BadScope.cs:66
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...
Definition BadScope.cs:74
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadScope.cs:83
BadMemberChangingEvent(BadObject mInstance, BadMemberInfo mMember, BadObject mOldValue, BadObject mNewValue)
Definition BadScope.cs:93
BadObject SetValue(BadExecutionContext ctx, BadObject[] args)
Definition BadScope.cs:168
static BadClassPrototype Prototype
Definition BadScope.cs:125
readonly BadObjectReference m_MemberTypeReference
Definition BadScope.cs:132
readonly BadObjectReference m_NameReference
Definition BadScope.cs:127
readonly BadObjectReference m_GetValueReference
Definition BadScope.cs:129
BadObject GetValue(BadExecutionContext ctx, BadObject[] args)
Definition BadScope.cs:163
override BadClassPrototype GetPrototype()
Definition BadScope.cs:224
BadMemberInfo(string name, BadScope scope)
Definition BadScope.cs:134
readonly BadObjectReference m_GetAttributesReference
Definition BadScope.cs:128
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...
Definition BadScope.cs:186
readonly BadObjectReference m_SetValueReference
Definition BadScope.cs:130
override string ToSafeString(List< BadObject > done)
Definition BadScope.cs:229
BadObject GetAttributes(BadExecutionContext ctx, BadObject[] args)
Definition BadScope.cs:153
readonly BadObjectReference m_IsReadonlyReference
Definition BadScope.cs:131
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadScope.cs:202
static readonly BadNativeClassPrototype< BadMemberInfo > s_Prototype
Definition BadScope.cs:119
Implements the Scope for the Script Engine.
Definition BadScope.cs:238
BadScope(string name, BadInteropExtensionProvider provider, BadTable locals, BadScope? caller=null, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a new Scope.
Definition BadScope.cs:320
readonly BadTable m_ScopeVariables
The Scope Variables.
Definition BadScope.cs:257
BadScope GetRootScope()
Returns the Root Scope of the Scope.
Definition BadScope.cs:521
BadScope CreateChild(string name, BadScope? caller, bool? useVisibility, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a subscope of the current scope.
Definition BadScope.cs:792
BadScopeFlags Flags
The Scope Flags.
Definition BadScope.cs:394
BadInteropExtensionProvider Provider
The Extension Provider.
Definition BadScope.cs:368
BadScope? m_Caller
The Caller of the Current Scope.
Definition BadScope.cs:282
readonly Dictionary< string, BadObject[]> m_Attributes
Definition BadScope.cs:259
bool IsContinue
Is true if the Continue Keyword was set.
Definition BadScope.cs:409
readonly Dictionary< Type, object > m_SingletonCache
The Singleton Cache.
Definition BadScope.cs:272
BadObjectReference GetVariable(string name, BadScope caller)
Returns the variable reference of the specified variable.
Definition BadScope.cs:1018
BadTable GetTable()
Returns the Variable Table of the current scope.
Definition BadScope.cs:778
readonly List< string > m_RegisteredApis
A List of Registered APIs.
Definition BadScope.cs:252
override BadClassPrototype GetPrototype()
Returns the Class Prototype for the Scope.
Definition BadScope.cs:596
bool HasVariable(string name, BadScope caller)
returns true if the specified variable is defined in the current scope or any parent scope
Definition BadScope.cs:1072
IEnumerable< BadObject > InitializeAttributes()
Definition BadScope.cs:861
readonly bool m_UseVisibility
Indicates if the Scope uses the visibility subsystem.
Definition BadScope.cs:277
void DefineProperty(string name, BadClassPrototype type, BadExpression getAccessor, BadExpression? setAccessor, BadExecutionContext caller, BadObject[] attributes)
Definition BadScope.cs:885
bool IsVisibleParentOf(BadScope scope)
Returns true if the specified scope is visible to the current scope.
Definition BadScope.cs:983
void SetContinue()
Sets the continue keyword inside this scope.
Definition BadScope.cs:698
bool IsBreak
Is true if the Break Keyword was set.
Definition BadScope.cs:404
string GetStackTrace()
Returns the Stack Trace of the Current scope.
Definition BadScope.cs:633
BadScope? Parent
The Parent Scope.
Definition BadScope.cs:384
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
Definition BadScope.cs:1079
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...
Definition BadScope.cs:1085
readonly BadInteropExtensionProvider m_Provider
The Extension Provider.
Definition BadScope.cs:247
string Name
The Name of the Scope (for Debugging)
Definition BadScope.cs:389
IReadOnlyCollection< string > RegisteredApis
A List of Registered APIs.
Definition BadScope.cs:363
BadScope(string name, BadInteropExtensionProvider provider, BadScope? caller=null, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a new Scope.
Definition BadScope.cs:298
IReadOnlyDictionary< string, BadObject[]> Attributes
Definition BadScope.cs:261
static BadScope CreateScope(BadExecutionContext ctx, string name, BadTable? locals=null)
Creates a Root Scope with the given name.
Definition BadScope.cs:608
BadPropertyInfo GetVariableInfo(string name)
Returns the variable info of the specified variable.
Definition BadScope.cs:946
bool OnChange(string name, BadObject oldValue, BadObject newValue)
Definition BadScope.cs:829
BadClass? ClassObject
The Class Object of the Scope.
Definition BadScope.cs:373
static BadClassPrototype Prototype
A Class Prototype for the Scope.
Definition BadScope.cs:420
static string GetStackTrace(BadScope scope)
Returns the Stack Trace of the given Scope.
Definition BadScope.cs:643
void Dispose()
Disposes the Scope and calls all finalizers.
Definition BadScope.cs:458
void SetExports(BadExecutionContext ctx, BadObject exports)
Definition BadScope.cs:722
void SetRegisteredApi(string api)
Registers an API.
Definition BadScope.cs:478
bool HasLocal(string name, BadScope caller, bool useExtensions=true)
returns true if the specified variable is defined in the current scope
Definition BadScope.cs:1061
void AddExport(string key, BadObject value)
Sets an exported key value pair in the scope.
Definition BadScope.cs:737
readonly List< Action > m_Finalizers
The Finalizer List of the Scope.
Definition BadScope.cs:242
BadObject? ReturnValue
The Return value of the scope.
Definition BadScope.cs:414
void SetReturnValue(BadObject? value)
Sets the Return value of this scope.
Definition BadScope.cs:759
BadObject? m_Exports
Contains the exported variables of the scope.
Definition BadScope.cs:287
bool CountInStackTrace
Indicates if the Scope should count towards the Stack Trace.
Definition BadScope.cs:399
override string ToSafeString(List< BadObject > done)
Definition BadScope.cs:1092
static BadScopeFlags ClearCaptures(BadScopeFlags flags)
Clears all Capture Flags from the given Flags.
Definition BadScope.cs:666
void SetCaller(BadScope? caller)
Sets the Caller of the Scope.
Definition BadScope.cs:512
void SetBreak()
Sets the break keyword inside this scope.
Definition BadScope.cs:679
BadObjectReference GetVariable(string name)
Returns a variable reference of the specified variable.
Definition BadScope.cs:1049
void AddFinalizer(Action finalizer)
Adds a Finalizer to the Scope.
Definition BadScope.cs:498
static BadPropertyVisibility GetPropertyVisibility(string propName)
Returns the visibility of the specified property.
Definition BadScope.cs:966
BadObject GetExports()
Returns the exported key value pairs of the scope.
Definition BadScope.cs:717
void DefineVariable(string name, BadObject value, BadScope? caller=null, BadPropertyInfo? info=null, BadObject[]? attributes=null)
Defines a new Variable in the current scope.
Definition BadScope.cs:929
void OnChanged(string name, BadObject oldValue, BadObject newValue)
Definition BadScope.cs:806
void SetFlags(BadScopeFlags flags)
Sets the Scope Flags.
Definition BadScope.cs:624
BadScope(BadScope parent, BadScope? caller, string name, BadScopeFlags flags=BadScopeFlags.RootScope, bool useVisibility=false)
Creates a new Scope.
Definition BadScope.cs:344
BadFunction? FunctionObject
The Function Object of the Scope.
Definition BadScope.cs:378
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:129
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< BadObject > getter, Action< BadObject, BadPropertyInfo?>? setter=null, Action? delete=null)
Creates a new Reference Object.
void Set(BadObject obj, BadPropertyInfo? info=null, bool noChangeEvent=false)
Sets the Referenced Object to a new Value.
Stores Meta Information about a Property.
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.
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
void SetChangeInterceptor(Func< string, BadObject, BadObject, bool >? interceptor)
Definition BadTable.cs:19
Dictionary< string, BadObject > InnerTable
The Inner Table for this Object.
Definition BadTable.cs:60
Implements a function that can be called from the script.
The Any Prototype, Base type for all types.
static readonly BadAnyPrototype Instance
The Instance of the BadAnyPrototype.
Implements a Type Instance in the BadScript Language.
Definition BadClass.cs:11
BadObjectReference GetProperty(string propName, BadPropertyVisibility visibility, BadScope? caller=null)
Gets a property from this class or any of its base classes.
Definition BadClass.cs:116
bool InheritsFrom(BadClassPrototype proto)
Returns true if the given object is an instance of the specified prototype.
Definition BadClass.cs:60
Implements a Class Prototype for the BadScript Language.
Helper Class that Builds a Native Class from a Prototype.
static readonly BadInterfacePrototype MemberChangedEventArgs
static readonly BadInterfacePrototype MemberChangingEventArgs
static BadClassPrototype GetNative(string name)
Returns a Native Class Prototype for the given Native Type.
static readonly BadInterfacePrototype InitializeAttribute
Implements the Interface for Native Boolean.
Definition IBadBoolean.cs:7
Implements the Interface for Native Strings.
Definition IBadString.cs:7
Contains the Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Function Classes 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
BadPropertyVisibility
The Visibility of a Property.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.
BadScopeFlags
Defines Different Behaviours for the Current Scope.