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 );
35
39 private readonly BadObjectReference m_Current;
40
44 private readonly IEnumerator<BadObject> m_Enumerator;
45
49 private readonly BadObjectReference m_Next;
50
55 public BadInteropEnumerator(IEnumerator<BadObject> enumerator)
56 {
57 m_Enumerator = enumerator;
58
60 _ => m_Enumerator.MoveNext(),
62 );
63
65 _ => m_Enumerator.Current,
67 );
68
69 m_Next = BadObjectReference.Make("BadArrayEnumerator.MoveNext", (p) => next);
70 m_Current = BadObjectReference.Make("BadArrayEnumerator.GetCurrent", (p) => current);
71 }
72
73#region IBadEnumerator Members
74
79 public bool MoveNext()
80 {
81 return m_Enumerator.MoveNext();
82 }
83
87 public void Reset()
88 {
89 m_Enumerator.Reset();
90 }
91
95 public BadObject Current => m_Enumerator.Current!;
96
100 object IEnumerator.Current => m_Enumerator.Current!;
101
105 public void Dispose()
106 {
107 m_Enumerator.Dispose();
108 }
109
110#endregion
111
114 {
115 return s_Prototype;
116 }
117
119 public override bool HasProperty(string propName, BadScope? caller = null)
120 {
121 return propName is "MoveNext" or "GetCurrent" ||
122 base.HasProperty(propName, caller);
123 }
124
126 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
127 {
128 switch (propName)
129 {
130 case "MoveNext":
131 return m_Next;
132 case "GetCurrent":
133 return m_Current;
134 }
135
136 return base.GetProperty(propName, caller);
137 }
138
140 public override string ToSafeString(List<BadObject> done)
141 {
142 return "InteropEnumerator";
143 }
144}
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