|
@@ -12,7 +12,7 @@ namespace MoonSharp.Interpreter.Interop
|
|
|
public class CustomConvertersCollection
|
|
public class CustomConvertersCollection
|
|
|
{
|
|
{
|
|
|
private Dictionary<Type, Func<DynValue, object>>[] m_Script2Clr = new Dictionary<Type, Func<DynValue, object>>[(int)LuaTypeExtensions.MaxConvertibleTypes + 1];
|
|
private Dictionary<Type, Func<DynValue, object>>[] m_Script2Clr = new Dictionary<Type, Func<DynValue, object>>[(int)LuaTypeExtensions.MaxConvertibleTypes + 1];
|
|
|
- private Dictionary<Type, Func<object, DynValue>> m_Clr2Script = new Dictionary<Type, Func<object, DynValue>>();
|
|
|
|
|
|
|
+ private Dictionary<Type, Func<Script, object, DynValue>> m_Clr2Script = new Dictionary<Type, Func<Script, object, DynValue>>();
|
|
|
|
|
|
|
|
internal CustomConvertersCollection()
|
|
internal CustomConvertersCollection()
|
|
|
{
|
|
{
|
|
@@ -65,7 +65,7 @@ namespace MoonSharp.Interpreter.Interop
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="clrDataType">The CLR data type.</param>
|
|
/// <param name="clrDataType">The CLR data type.</param>
|
|
|
/// <param name="converter">The converter, or null.</param>
|
|
/// <param name="converter">The converter, or null.</param>
|
|
|
- public void SetClrToScriptCustomConversion(Type clrDataType, Func<object, DynValue> converter = null)
|
|
|
|
|
|
|
+ public void SetClrToScriptCustomConversion(Type clrDataType, Func<Script, object, DynValue> converter = null)
|
|
|
{
|
|
{
|
|
|
if (converter == null)
|
|
if (converter == null)
|
|
|
{
|
|
{
|
|
@@ -83,9 +83,9 @@ namespace MoonSharp.Interpreter.Interop
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <typeparam name="T">The CLR data type.</typeparam>
|
|
/// <typeparam name="T">The CLR data type.</typeparam>
|
|
|
/// <param name="converter">The converter, or null.</param>
|
|
/// <param name="converter">The converter, or null.</param>
|
|
|
- public void SetClrToScriptCustomConversion<T>(Func<T, DynValue> converter = null)
|
|
|
|
|
|
|
+ public void SetClrToScriptCustomConversion<T>(Func<Script, T, DynValue> converter = null)
|
|
|
{
|
|
{
|
|
|
- SetClrToScriptCustomConversion(typeof(T), o => converter((T)o));
|
|
|
|
|
|
|
+ SetClrToScriptCustomConversion(typeof(T), (s, o) => converter(s, (T)o));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -94,11 +94,32 @@ namespace MoonSharp.Interpreter.Interop
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="clrDataType">Type of the color data.</param>
|
|
/// <param name="clrDataType">Type of the color data.</param>
|
|
|
/// <returns>The converter function, or null if not found</returns>
|
|
/// <returns>The converter function, or null if not found</returns>
|
|
|
- public Func<object, DynValue> GetClrToScriptCustomConversion(Type clrDataType)
|
|
|
|
|
|
|
+ public Func<Script, object, DynValue> GetClrToScriptCustomConversion(Type clrDataType)
|
|
|
{
|
|
{
|
|
|
return m_Clr2Script.GetOrDefault(clrDataType);
|
|
return m_Clr2Script.GetOrDefault(clrDataType);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// Sets a custom converter from a CLR data type. Set null to remove a previous custom converter.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="clrDataType">The CLR data type.</param>
|
|
|
|
|
+ /// <param name="converter">The converter, or null.</param>
|
|
|
|
|
+ [Obsolete("This method is deprecated. Use the overloads accepting functions with a Script argument.")]
|
|
|
|
|
+ public void SetClrToScriptCustomConversion(Type clrDataType, Func<object, DynValue> converter = null)
|
|
|
|
|
+ {
|
|
|
|
|
+ SetClrToScriptCustomConversion(clrDataType, (s, o) => converter(o));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Sets a custom converter from a CLR data type. Set null to remove a previous custom converter.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <typeparam name="T">The CLR data type.</typeparam>
|
|
|
|
|
+ /// <param name="converter">The converter, or null.</param>
|
|
|
|
|
+ [Obsolete("This method is deprecated. Use the overloads accepting functions with a Script argument.")]
|
|
|
|
|
+ public void SetClrToScriptCustomConversion<T>(Func<T, DynValue> converter = null)
|
|
|
|
|
+ {
|
|
|
|
|
+ SetClrToScriptCustomConversion(typeof(T), o => converter((T)o));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// Removes all converters.
|
|
/// Removes all converters.
|