BadScript 2
Loading...
Searching...
No Matches
BadInteropEnumerator.cs
Go to the documentation of this file.
1using System.Collections;
2
8
10
15{
20 "Enumerator",
21 (_, _) => throw new BadRuntimeException("Cannot call method on enumerator"),
22 () => new []{(BadInterfacePrototype)BadNativeClassBuilder.Enumerator.CreateGeneric(new []{BadAnyPrototype.Instance})}
23 );
24
28 private readonly BadObjectReference m_Current;
29
33 private readonly IEnumerator<BadObject> m_Enumerator;
34
38 private readonly BadObjectReference m_Next;
39
44 public BadInteropEnumerator(IEnumerator<BadObject> enumerator)
45 {
46 m_Enumerator = enumerator;
48 "MoveNext",
49 _ => m_Enumerator.MoveNext(),
51 );
52
54 "GetCurrent",
55 _ => m_Enumerator.Current,
57 );
58
59 m_Next = BadObjectReference.Make("BadArrayEnumerator.MoveNext", () => next);
60 m_Current = BadObjectReference.Make("BadArrayEnumerator.GetCurrent", () => current);
61 }
62
67 public bool MoveNext()
68 {
69 return m_Enumerator.MoveNext();
70 }
71
75 public void Reset()
76 {
77 m_Enumerator.Reset();
78 }
79
83 public BadObject Current => m_Enumerator.Current!;
84
88 object IEnumerator.Current => m_Enumerator.Current!;
89
93 public void Dispose()
94 {
95 m_Enumerator.Dispose();
96 }
97
100 {
101 return s_Prototype;
102 }
103
105 public override bool HasProperty(string propName, BadScope? caller = null)
106 {
107 return propName is "MoveNext" or "GetCurrent" ||
108 base.HasProperty(propName, caller);
109 }
110
112 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
113 {
114 switch (propName)
115 {
116 case "MoveNext":
117 return m_Next;
118 case "GetCurrent":
119 return m_Current;
120 }
121
122 return base.GetProperty(propName, caller);
123 }
124
126 public override string ToSafeString(List<BadObject> done)
127 {
128 return "InteropEnumerator";
129 }
130}
Implements the Scope for the Script Engine.
Definition BadScope.cs:238
Implements a simple wrapper for C# IEnumerators to be used in BS2.
bool MoveNext()
Moves the Enumerator to the next element.
override string ToSafeString(List< BadObject > done)
readonly IEnumerator< BadObject > m_Enumerator
The Internal Enumerator.
readonly BadObjectReference m_Current
Current Function Reference.
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 BadObjectReference m_Next
GetNext Function Reference.
static readonly BadClassPrototype s_Prototype
The Prototype for the Interop Enumerator Object.
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
BadInteropEnumerator(IEnumerator< BadObject > enumerator)
Creates a new Interop Enumerator.
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
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.
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.
static readonly BadInterfacePrototype Enumerator
The IEnumerator Interface Prototype.
BadObject CreateGeneric(BadObject[] args)
Resolves the Generic Object to a concrete type.
Defines a BadScript Enumerator.
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 Interface Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10