1using System.Collections;
29 private readonly Dictionary<string, BadObjectReference>
m_ReferenceCache =
new Dictionary<string, BadObjectReference>();
36 InnerTable =
new Dictionary<string, BadObject>();
44 public BadTable(Dictionary<string, BadObject> table)
49 foreach (KeyValuePair<string, BadObject> kvp
in InnerTable)
75 new Dictionary<string, BadObject>
94 IEnumerator IEnumerable.GetEnumerator()
131 return InnerTable.ContainsKey(propName) || caller !=
null && caller.Provider.HasObject<
BadTable>(propName);
170 $
"BadTable.{propName}",
176 BadPropertyInfo info = GetPropertyInfo(propName);
178 if (propValue != Null && info.IsReadOnly)
180 throw new BadRuntimeException($
"{propName} is read-only");
183 if (info.Type !=
null && !info.Type.IsAssignableFrom(o))
185 throw new BadRuntimeException(
186 $
"Cannot assign object {o.GetType().Name} to property '{propName}' of type '{info.Type.Name}'"
191 var oldValueRef = propRef.Dereference();
204 if (t?.Type !=
null && !t.Type.IsAssignableFrom(o))
207 $
"Cannot assign object {o.GetType().Name} to property '{propName}' of type '{t.Type.Name}'"
229 if (!InnerTable.ContainsKey(propName) && caller !=
null && caller.Provider.HasObject<
BadTable>(propName))
231 return caller.Provider.GetObjectReference(GetType(), propName,
this, caller);
234 return GetLocalReference(propName);
243 StringBuilder sb =
new StringBuilder();
247 foreach (KeyValuePair<string, BadObject> kvp
in InnerTable)
251 sb.AppendLine(
"RECURSION_PROTECT");
256 string kStr = kvp.Key;
258 string vStr =
"{...}";
260 if (!done.Contains(kvp.Value))
262 vStr = kvp.Value.ToSafeString(done).Trim();
265 if (kStr.Contains(
"\n"))
267 kStr = kStr.Replace(
"\n",
"\n\t");
270 if (vStr.Contains(
"\n"))
272 vStr = vStr.Replace(
"\n",
"\n\t");
275 sb.AppendLine($
"\t{kStr}: {vStr}");
280 return sb.ToString();
Implements the Scope for the Script Engine.
Gets thrown by the runtime.
The Base Class for all BadScript Objects.
static readonly BadObject Null
The Null Value for the BadScript Language.
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.
Stores Meta Information about a Property.
Implements a Table Structure for the BadScript Language.
BadObjectReference GetProperty(string propName, bool useExtensions, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
override BadClassPrototype GetPrototype()
bool OnChangePropertyInternal(string propName, BadObject oldValue, BadObject newValue)
Func< string, BadObject, BadObject, bool >? m_OnChangeProperty
static ? BadClassPrototype s_Prototype
The Prototype for the BadScript Table.
Action< string, BadObject, BadObject > OnChangedProperty
readonly Dictionary< string, BadObjectReference > m_ReferenceCache
BadTable(Dictionary< string, BadObject > table)
Creates a new Table Object.
override string ToSafeString(List< BadObject > done)
void SetChangeInterceptor(Func< string, BadObject, BadObject, bool >? interceptor)
Dictionary< string, BadPropertyInfo > PropertyInfos
A Table of additional property information.
BadTable()
Creates a new Table Object.
BadObjectReference GetLocalReference(string propName)
Returns a Reference to a Local Property with the given Name.
static BadClassPrototype Prototype
IEnumerator< BadObject > GetEnumerator()
Returns the Enumerator for this Table.
Dictionary< string, BadObject > InnerTable
The Inner Table for this Object.
bool RemoveKey(string key)
Removes a Property from the Table.
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...
BadPropertyInfo GetPropertyInfo(string propName)
Returns Property Information for a given Key.
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
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 Enumerable.
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains Runtime Type Objects.
Contains the Runtime Objects.