20 new Dictionary<string, Func<BadObject, BadObject>>();
25 private readonly Dictionary<Type, Dictionary<string, Func<BadObject, BadObject>>>
m_ObjectExtensions =
26 new Dictionary<Type, Dictionary<string, Func<BadObject, BadObject>>>();
32 new Dictionary<Type, Dictionary<string, Func<BadObject, BadObject>>>();
34 private readonly Dictionary<Type, bool>
m_SupportedTypes =
new Dictionary<Type, bool>();
67 Type t = obj.GetType();
80 return objs.ToArray();
92 return objs.ToArray();
103 Type t = obj.GetType();
105 Dictionary<string, BadObject> objs =
new Dictionary<string, BadObject>(
m_GlobalExtensions.ToDictionary(x => x.Key, x => x.Value(obj)));
109 foreach (KeyValuePair<
string,Func<BadObject,BadObject>> kvp
in GetTypeExtensions(t))
111 objs[kvp.Key] = kvp.Value(obj);
117 return new BadTable(objs.ToDictionary(x=>x.Key, x => x.Value));
124 foreach (KeyValuePair<
string,Func<BadObject,BadObject>> kvp
in GetTypeExtensions(t))
126 objs[kvp.Key] = kvp.Value(obj);
130 return new BadTable(objs.ToDictionary(x=>x.Key, x => x.Value));
168 if (
m_StaticExtensionCache.TryGetValue(type, out Dictionary<
string, Func<BadObject, BadObject>>? extensions))
173 Dictionary<string, Func<BadObject, BadObject>>
174 exts =
new Dictionary<string, Func<BadObject, BadObject>>();
176 foreach (KeyValuePair<Type, Dictionary<
string, Func<BadObject, BadObject>>> kvp
in
179 foreach (KeyValuePair<
string, Func<BadObject, BadObject>> keyValuePair
in kvp.Value)
181 exts[keyValuePair.Key] = keyValuePair.Value;
255 public void RegisterObject(Type t,
string propName, Func<BadObject, BadObject> obj)
257 if (
m_ObjectExtensions.TryGetValue(t, out Dictionary<
string, Func<BadObject, BadObject>>? extension))
259 extension[propName] = obj;
263 m_ObjectExtensions[t] =
new Dictionary<string, Func<BadObject, BadObject>> { { propName, obj } };
279 .ContainsKey(propName));
307 (p) =>
GetObject(t, propName, instance, caller, p)
323 if (ext.ContainsKey(propName))
325 return ext[propName](instance);
347 return GetObject(typeof(T), propName, instance, caller, pos);
Describes a specific position inside a source file.
Implements the Scope for the Script Engine.
Gets thrown by the runtime.
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
Public Extension API for the BS2 Runtime.
void InnerAddExtensions(BadInteropExtensionProvider provider)
Adds the Extensions to the given Provider.
void RegisterObject(Type t, string propName, Func< BadObject, BadObject > obj)
Registers the specified extension for the specified type.
readonly List< Type > m_ActiveExtensions
List of all active extensions.
BadObject GetObject(Type t, string propName, BadObject instance, BadScope? caller, BadSourcePosition? pos)
Returns the specified extension.
void RegisterObject(Type t, string propName, BadObject obj)
Registers the specified extension for the specified type.
BadTable GetExtensions(BadObject obj)
Returns all Extension Names for the specified object.
void RegisterGlobal(string propName, Func< BadObject, BadObject > func)
Registers the specified extension for all objects.
readonly Dictionary< Type, bool > m_SupportedTypes
BadInteropExtensionProvider()
Creates a new BadInteropExtensionProvider.
bool HasObject< T >(string propName)
Returns True if the specified type has the specified extension.
readonly Dictionary< Type, Dictionary< string, Func< BadObject, BadObject > > > m_StaticExtensionCache
Cache for already built extension tables.
BadObjectReference GetObjectReference(Type t, string propName, BadObject instance, BadScope? caller)
Returns a reference to the specified extension.
void RegisterObject< T >(string propName, Func< T, BadObject > obj)
Registers the specified extension for the specified type.
BadObject[] GetExtensionNames(BadObject obj)
Returns all Extension Names for the specified object.
bool InnerHasTypeExtensions(Type t)
void AddExtension(BadInteropExtension extension)
Adds the specified extension to the list of registered extensions.
Dictionary< string, Func< BadObject, BadObject > > GetTypeExtensions(Type type)
Returns all type extensions for the specified type.
bool HasGlobalExtensions(string propName)
Returns true if a global extension with the specified name is available.
void AddExtensions(params BadInteropExtension[] extensions)
Adds the specified extensions to the list of registered extensions.
BadObject GetObject< T >(string propName, BadObject instance, BadScope? caller=null, BadSourcePosition? pos=null)
Returns the specified extension.
void RegisterGlobal(string propName, BadObject obj)
Registers the specified extension for all objects.
readonly Dictionary< Type, Dictionary< string, Func< BadObject, BadObject > > > m_ObjectExtensions
Object Extensions that are available for objects of the specified type.
void AddExtension< T >()
Adds an Extension Class to the List of registered extensions.
BadInteropExtensionProvider(BadInteropExtension[] extensions)
Creates a new BadInteropExtensionProvider.
bool HasObject(Type t, string propName)
Returns True if the specified type has the specified extension.
BadObject[] GetExtensionNames()
Returns all Global Extension names.
bool HasTypeExtensions(Type t)
Returns true if any extensions are available for the specified object(excluding global extensions)
readonly Dictionary< string, Func< BadObject, BadObject > > m_GlobalExtensions
Global extensions that are available for all objects in the runtime.
void Initialize(BadInteropExtension ext)
Initializes the extension.
The Base Class for all BadScript Objects.
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.
Implements a Table Structure for the BadScript Language.
Implements a Native Type.
T Value
The Value of the Native Type.
Defines Settings for Native Optimizations.
static T Instance
Returns the Instance of the Settings Provider.
Defines properties for Native Types.
Contains Shared Data Structures and Functionality.
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Native Runtime Objects.
Contains the Runtime Objects.
Contains Runtime Settings Objects.