BadScript 2
Loading...
Searching...
No Matches
BadInteropEnumerator.cs
Go to the documentation of this file.
1using System.Collections;
2
8
10
15{
19 private static readonly BadClassPrototype s_Prototype =
21 (_, _) =>
22 throw new
23 BadRuntimeException("Cannot call method on enumerator"
24 ),
25 () => new[]
26 {
28 .Enumerator.CreateGeneric(new[]
29 {
30 BadAnyPrototype.Instance,
31 }
32 ),
33 },
34 null
35 );
36
40 private readonly BadObjectReference m_Current;
41
45 private readonly IEnumerator<BadObject> m_Enumerator;
46
50 private readonly BadObjectReference m_Next;
51
56 public BadInteropEnumerator(IEnumerator<BadObject> enumerator)
57 {
58 m_Enumerator = enumerator;
59
61 _ => m_Enumerator.MoveNext(),
63 );
64
66 _ => m_Enumerator.Current,
68 );
69
70 m_Next = BadObjectReference.Make("BadArrayEnumerator.MoveNext", (p) => next);
71 m_Current = BadObjectReference.Make("BadArrayEnumerator.GetCurrent", (p) => current);
72 }
73
74#region IBadEnumerator Members
75
80 public bool MoveNext()
81 {
82 return m_Enumerator.MoveNext();
83 }
84
88 public void Reset()
89 {
90 m_Enumerator.Reset();
91 }
92
96 public BadObject Current => m_Enumerator.Current!;
97
101 object IEnumerator.Current => m_Enumerator.Current!;
102
106 public void Dispose()
107 {
108 m_Enumerator.Dispose();
109 }
110
111#endregion
112
115 {
116 return s_Prototype;
117 }
118
120 public override bool HasProperty(string propName, BadScope? caller = null)
121 {
122 return propName is "MoveNext" or "GetCurrent" ||
123 base.HasProperty(propName, caller);
124 }
125
127 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
128 {
129 switch (propName)
130 {
131 case "MoveNext":
132 return m_Next;
133 case "GetCurrent":
134 return m_Current;
135 }
136
137 return base.GetProperty(propName, caller);
138 }
139
141 public override string ToSafeString(List<BadObject> done)
142 {
143 return "InteropEnumerator";
144 }
145}
Implements the Scope for the Script Engine.
Definition BadScope.cs:16
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:141
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.
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.
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