Browse Source

Build fixed + proxy objects revised.

Xanathar 10 years ago
parent
commit
43022d8bbd
16 changed files with 353 additions and 165 deletions
  1. 2 5
      src/MoonSharp.Interpreter.Tests/EndToEnd/ProxyObjectsTests.cs
  2. 3 0
      src/MoonSharp.Interpreter.Tests/_Projects/MoonSharp.Interpreter.Tests.Embeddable.portable40/MoonSharp.Interpreter.Tests.Embeddable.portable40.csproj
  3. 3 0
      src/MoonSharp.Interpreter.Tests/_Projects/MoonSharp.Interpreter.Tests.net40-client/MoonSharp.Interpreter.Tests.net40-client.csproj
  4. 3 0
      src/MoonSharp.Interpreter.Tests/_Projects/MoonSharp.Interpreter.Tests.portable40/MoonSharp.Interpreter.Tests.portable40.csproj
  5. 31 10
      src/MoonSharp.Interpreter/DataTypes/UserData.cs
  6. 43 65
      src/MoonSharp.Interpreter/Interop/CustomConvertersCollection.cs
  7. 28 11
      src/MoonSharp.Interpreter/Interop/ProxyObjects/DelegateProxyFactory.cs
  8. 42 0
      src/MoonSharp.Interpreter/Interop/ProxyObjects/IProxyFactory.cs
  9. 0 26
      src/MoonSharp.Interpreter/Interop/ProxyObjects/IScriptProxyObjectFactory.cs
  10. 0 29
      src/MoonSharp.Interpreter/Interop/StandardDescriptors/EnumDescriptor.cs
  11. 127 0
      src/MoonSharp.Interpreter/Interop/StandardDescriptors/ProxyUserDataDescriptor.cs
  12. 38 12
      src/MoonSharp.Interpreter/Interop/UserDataRegistries/TypeDescriptorRegistry.cs
  13. 2 0
      src/MoonSharp.Interpreter/Loaders/UnityAssetsScriptLoader.cs
  14. 3 3
      src/MoonSharp.Interpreter/MoonSharp.Interpreter.net35-client.csproj
  15. 14 2
      src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.net40-client/MoonSharp.Interpreter.net40-client.csproj
  16. 14 2
      src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.portable40/MoonSharp.Interpreter.portable40.csproj

+ 2 - 5
src/MoonSharp.Interpreter.Tests/EndToEnd/ProxyObjectsTests.cs

@@ -27,15 +27,12 @@ namespace MoonSharp.Interpreter.Tests.EndToEnd
 		[Test]
 		public void ProxyTest()
 		{
-			Script.GlobalOptions.CustomConverters.RegisterProxy<Proxy, Random>(
-				r => new Proxy(r), p => p.random);
-
-			UserData.RegisterType<Proxy>();
+			UserData.RegisterProxyType<Proxy, Random>(r => new Proxy(r));
 
 			Script S = new Script();
 
 			S.Globals["R"] = new Random();
-			S.Globals["func"] = (Action<Random>)(r => { Assert.IsNotNull(r); Assert.IsInstanceOf(typeof(Random), r); });
+			S.Globals["func"] = (Action<Random>)(r => { Assert.IsNotNull(r); Assert.IsTrue(r is Random); });
 
 			S.DoString(@"
 				x = R.GetValue();

+ 3 - 0
src/MoonSharp.Interpreter.Tests/_Projects/MoonSharp.Interpreter.Tests.Embeddable.portable40/MoonSharp.Interpreter.Tests.Embeddable.portable40.csproj

@@ -98,6 +98,9 @@
       <SubType>Code</SubType>
       <Link>MetatableTests.cs</Link>
     </Compile>
+    <Compile Include="..\..\EndToEnd\ProxyObjectsTests.cs">
+      <Link>ProxyObjectsTests.cs</Link>
+    </Compile>
     <Compile Include="..\..\EndToEnd\StringLibTests.cs">
       <Link>StringLibTests.cs</Link>
     </Compile>

+ 3 - 0
src/MoonSharp.Interpreter.Tests/_Projects/MoonSharp.Interpreter.Tests.net40-client/MoonSharp.Interpreter.Tests.net40-client.csproj

@@ -114,6 +114,9 @@
       <SubType>Code</SubType>
       <Link>MetatableTests.cs</Link>
     </Compile>
+    <Compile Include="..\..\EndToEnd\ProxyObjectsTests.cs">
+      <Link>ProxyObjectsTests.cs</Link>
+    </Compile>
     <Compile Include="..\..\EndToEnd\StringLibTests.cs">
       <Link>StringLibTests.cs</Link>
     </Compile>

+ 3 - 0
src/MoonSharp.Interpreter.Tests/_Projects/MoonSharp.Interpreter.Tests.portable40/MoonSharp.Interpreter.Tests.portable40.csproj

@@ -114,6 +114,9 @@
       <SubType>Code</SubType>
       <Link>MetatableTests.cs</Link>
     </Compile>
+    <Compile Include="..\..\EndToEnd\ProxyObjectsTests.cs">
+      <Link>ProxyObjectsTests.cs</Link>
+    </Compile>
     <Compile Include="..\..\EndToEnd\StringLibTests.cs">
       <Link>StringLibTests.cs</Link>
     </Compile>

+ 31 - 10
src/MoonSharp.Interpreter/DataTypes/UserData.cs

@@ -72,6 +72,37 @@ namespace MoonSharp.Interpreter
 			return TypeDescriptorRegistry.RegisterType_Impl(type, accessMode, friendlyName, null);
 		}
 
+
+		/// <summary>
+		/// Registers a proxy type.
+		/// </summary>
+		/// <param name="proxyFactory">The proxy factory.</param>
+		/// <param name="accessMode">The access mode.</param>
+		/// <param name="friendlyName">A friendly name for the descriptor.</param>
+		/// <returns></returns>
+		public static IUserDataDescriptor RegisterProxyType(IProxyFactory proxyFactory, InteropAccessMode accessMode = InteropAccessMode.Default, string friendlyName = null)
+		{
+			return TypeDescriptorRegistry.RegisterProxyType_Impl(proxyFactory, accessMode, friendlyName);
+		}
+
+		/// <summary>
+		/// Registers a proxy type using a delegate.
+		/// </summary>
+		/// <typeparam name="TProxy">The type of the proxy.</typeparam>
+		/// <typeparam name="TTarget">The type of the target.</typeparam>
+		/// <param name="wrapDelegate">A delegate creating a proxy object from a target object.</param>
+		/// <param name="accessMode">The access mode.</param>
+		/// <param name="friendlyName">A friendly name for the descriptor.</param>
+		/// <returns></returns>
+		public static IUserDataDescriptor RegisterProxyType<TProxy, TTarget>(Func<TTarget, TProxy> wrapDelegate, InteropAccessMode accessMode = InteropAccessMode.Default, string friendlyName = null)
+			where TProxy : class
+			where TTarget : class
+		{
+			return RegisterProxyType(new DelegateProxyFactory<TProxy, TTarget>(wrapDelegate), accessMode, friendlyName);
+		}
+
+
+
 		/// <summary>
 		/// Registers a type with a custom userdata descriptor
 		/// </summary>
@@ -263,16 +294,6 @@ namespace MoonSharp.Interpreter
 			return ExtensionMethodsRegistry.GetExtensionMethodsByNameAndType(name, extendedType);
 		}
 
-		/// <summary>
-		/// Gets all the extension methods which can match a given name
-		/// </summary>
-		/// <param name="name">The name.</param>
-		/// <returns></returns>
-		//public static IEnumerable<IOverloadableMemberDescriptor> GetExtensionMethodsByName(string name)
-		//{
-		//	return ExtensionMethodsRegistry.GetExtensionMethodsByName(name);
-		//}
-
 		/// <summary>
 		/// Gets a number which gets incremented everytime the extension methods registry changes.
 		/// Use this to invalidate caches based on extension methods

+ 43 - 65
src/MoonSharp.Interpreter/Interop/CustomConvertersCollection.cs

@@ -12,59 +12,67 @@ namespace MoonSharp.Interpreter.Interop
 	public class CustomConvertersCollection 
 	{
 		private Dictionary<Type, Func<DynValue, object>>[] m_Script2Clr = new Dictionary<Type, Func<DynValue, object>>[(int)LuaTypeExtensions.MaxConvertibleTypes + 1];
-		private Dictionary<Type, Dictionary<Type, Func<object, object>>> m_Script2ClrUserData = new Dictionary<Type, Dictionary<Type, Func<object, object>>>();
 		private Dictionary<Type, Func<Script, object, DynValue>> m_Clr2Script = new Dictionary<Type, Func<Script, object, DynValue>>();
 
+
+
 		internal CustomConvertersCollection()
 		{
 			for (int i = 0; i < m_Script2Clr.Length; i++)
 				m_Script2Clr[i] = new Dictionary<Type, Func<DynValue, object>>();
 		}
 
-		public void SetScriptToClrUserDataSpecificCustomConversion(Type destType, Type userDataType, Func<object, object> converter = null)
-		{
-			var destTypeMap = m_Script2ClrUserData.GetOrCreate(destType, () => new Dictionary<Type, Func<object, object>>());
-			destTypeMap[userDataType] = converter;
+		// This needs to be evaluated further (doesn't work well with inheritance)
+		//
+		// 		private Dictionary<Type, Dictionary<Type, Func<object, object>>> m_Script2ClrUserData = new Dictionary<Type, Dictionary<Type, Func<object, object>>>();
+		//
+		//public void SetScriptToClrUserDataSpecificCustomConversion(Type destType, Type userDataType, Func<object, object> converter = null)
+		//{
+		//	var destTypeMap = m_Script2ClrUserData.GetOrCreate(destType, () => new Dictionary<Type, Func<object, object>>());
+		//	destTypeMap[userDataType] = converter;
 
-			SetScriptToClrCustomConversion(DataType.UserData, destType, v => DispatchUserDataCustomConverter(destTypeMap, v));
-		}
+		//	SetScriptToClrCustomConversion(DataType.UserData, destType, v => DispatchUserDataCustomConverter(destTypeMap, v));
+		//}
 
-		private object DispatchUserDataCustomConverter(Dictionary<Type, Func<object, object>> destTypeMap, DynValue v)
-		{
-			if (v.Type != DataType.UserData)
-				return null;
+		//private object DispatchUserDataCustomConverter(Dictionary<Type, Func<object, object>> destTypeMap, DynValue v)
+		//{
+		//	if (v.Type != DataType.UserData)
+		//		return null;
 
-			if (v.UserData.Object == null)
-				return null;
+		//	if (v.UserData.Object == null)
+		//		return null;
 
-			Type userDataType = v.UserData.Object.GetType();
+		//	Func<object, object> converter;
 
-			Func<object, object> converter;
+		//	for (Type userDataType = v.UserData.Object.GetType();
+		//		userDataType != typeof(object);
+		//		userDataType = userDataType.BaseType)
+		//	{
+		//		if (destTypeMap.TryGetValue(userDataType, out converter))
+		//		{
+		//			return converter(v.UserData.Object);
+		//		}
+		//	}
 
-			if (destTypeMap.TryGetValue(userDataType, out converter))
-			{
-				return converter(v.UserData.Object);
-			}
+		//	return null;
+		//}
 
-			return null;
-		}
+		//public Func<object, object> GetScriptToClrUserDataSpecificCustomConversion(Type destType, Type userDataType)
+		//{
+		//	Dictionary<Type, Func<object, object>> destTypeMap;
 
-		public Func<object, object> GetScriptToClrUserDataSpecificCustomConversion(Type destType, Type userDataType)
-		{
-			Dictionary<Type, Func<object, object>> destTypeMap;
+		//	if (m_Script2ClrUserData.TryGetValue(destType, out destTypeMap))
+		//	{
+		//		Func<object, object> converter;
 
-			if (m_Script2ClrUserData.TryGetValue(destType, out destTypeMap))
-			{
-				Func<object, object> converter;
+		//		if (destTypeMap.TryGetValue(userDataType, out converter))
+		//		{
+		//			return converter;
+		//		}
+		//	}
 
-				if (destTypeMap.TryGetValue(userDataType, out converter))
-				{
-					return converter;
-				}
-			}
-
-			return null;
-		}
+		//	return null;
+		//}
 
 
 
@@ -168,36 +176,6 @@ namespace MoonSharp.Interpreter.Interop
 		}
 
 
-		/// <summary>
-		/// Registers a proxy handler
-		/// </summary>
-		/// <typeparam name="TProxy">The type of the proxy.</typeparam>
-		/// <typeparam name="TTarget">The type of the target.</typeparam>
-		/// <param name="proxyHandler">The proxy handler.</param>
-		public void RegisterProxy<TProxy, TTarget>(IProxyHandler<TProxy, TTarget> proxyHandler)
-			where TProxy : class
-			where TTarget : class
-		{
-			SetClrToScriptCustomConversion<TTarget>((s, t) => DynValue.FromObject(s, proxyHandler.ProxyWrap(t)));
-			SetScriptToClrCustomConversion(DataType.UserData, typeof(TTarget), v => proxyHandler.ProxyUnwrap((TProxy)v.UserData.Object));
-		}
-
-		/// <summary>
-		/// Registers a proxy handler using DelegateProxyHandler and the specified delegates.
-		/// </summary>
-		/// <typeparam name="TProxy">The type of the proxy.</typeparam>
-		/// <typeparam name="TTarget">The type of the target.</typeparam>
-		/// <param name="wrapDelegate">The wrap delegate.</param>
-		/// <param name="unwrapDelegate">The unwrap delegate.</param>
-		public void RegisterProxy<TProxy, TTarget>(Func<TTarget, TProxy> wrapDelegate, Func<TProxy, TTarget> unwrapDelegate)
-			where TProxy : class
-			where TTarget : class
-		{
-			RegisterProxy(new DelegateProxyHandler<TProxy, TTarget>(wrapDelegate, unwrapDelegate));
-		}
-
-
-
 		/// <summary>
 		/// Removes all converters.
 		/// </summary>

+ 28 - 11
src/MoonSharp.Interpreter/Interop/ProxyObjects/DelegateProxyObjectFactory.cs → src/MoonSharp.Interpreter/Interop/ProxyObjects/DelegateProxyFactory.cs

@@ -6,42 +6,59 @@ using System.Text;
 namespace MoonSharp.Interpreter.Interop
 {
 	/// <summary>
-	/// Implementation of IScriptProxyObjectFactory taking two delegates for simple instancing of proxies.
+	/// Implementation of IProxyFactory taking two delegates for simple instancing of proxies.
 	/// </summary>
 	/// <typeparam name="TProxy">The type of the proxy.</typeparam>
 	/// <typeparam name="TTarget">The type of the target.</typeparam>
-	public class DelegateProxyHandler<TProxy, TTarget> : IProxyHandler<TProxy, TTarget>
+	public class DelegateProxyFactory<TProxy, TTarget> : IProxyFactory<TProxy, TTarget>
 		where TProxy : class
 		where TTarget : class
 	{
 		Func<TTarget, TProxy> wrapDelegate;
-		Func<TProxy, TTarget> unwrapDelegate;
 
 		/// <summary>
-		/// Initializes a new instance of the <see cref="DelegateProxyHandler{TProxy, TTarget}"/> class.
+		/// Initializes a new instance of the <see cref="DelegateProxyFactory{TProxy, TTarget}"/> class.
 		/// </summary>
 		/// <param name="wrapDelegate">The proxy.</param>
 		/// <param name="unwrapDelegate">The deproxy.</param>
-		public DelegateProxyHandler(Func<TTarget, TProxy> wrapDelegate, Func<TProxy, TTarget> unwrapDelegate)
+		public DelegateProxyFactory(Func<TTarget, TProxy> wrapDelegate)
 		{
 			this.wrapDelegate = wrapDelegate;
-			this.unwrapDelegate = unwrapDelegate;
 		}
 
 		/// <summary>
-		/// Takes an instance of a proxy object and returns the real object behind it
+		/// Takes an instance of a target object and returns a proxy object wrapping it
 		/// </summary>
-		public TTarget ProxyUnwrap(TProxy proxyobj)
+		public TProxy CreateProxyObject(TTarget target)
 		{
-			return unwrapDelegate(proxyobj);
+			return wrapDelegate(target);
 		}
 
 		/// <summary>
 		/// Takes an instance of a target object and returns a proxy object wrapping it
 		/// </summary>
-		public TProxy ProxyWrap(TTarget target)
+		/// <param name="o"></param>
+		/// <returns></returns>
+		public object CreateProxyObject(object o)
 		{
-			return wrapDelegate(target);
+			return CreateProxyObject((TTarget)o);
+		}
+
+		/// <summary>
+		/// Gets the proxied type
+		/// </summary>
+		/// <returns></returns>
+		public Type TargetType
+		{
+			get { return typeof(TTarget); }
+		}
+
+		/// <summary>
+		/// Gets the proxy type
+		/// </summary>
+		public Type ProxyType
+		{
+			get { return typeof(TProxy); }
 		}
 	}
 

+ 42 - 0
src/MoonSharp.Interpreter/Interop/ProxyObjects/IProxyFactory.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.Interop
+{
+	/// <summary>
+	/// Interface for proxy objects (type unsafe version)
+	/// </summary>
+	public interface IProxyFactory
+	{
+		/// <summary>
+		/// Takes an instance of a target object and returns a proxy object wrapping it
+		/// </summary>
+		object CreateProxyObject(object o);
+		/// <summary>
+		/// Gets the proxied type
+		/// </summary>
+		Type TargetType { get; }
+		/// <summary>
+		/// Gets the proxy type
+		/// </summary>
+		Type ProxyType { get; }
+	}
+
+	/// <summary>
+	/// Interface for proxy objects (type safe version)
+	/// </summary>
+	/// <typeparam name="TProxy">The type of the proxy.</typeparam>
+	/// <typeparam name="TTarget">The type of the target.</typeparam>
+	public interface IProxyFactory<TProxy, TTarget> : IProxyFactory
+		where TProxy : class
+		where TTarget : class
+	{
+		/// <summary>
+		/// Takes an instance of a target object and returns a proxy object wrapping it
+		/// </summary>
+		TProxy CreateProxyObject(TTarget target);
+	}
+
+}

+ 0 - 26
src/MoonSharp.Interpreter/Interop/ProxyObjects/IScriptProxyObjectFactory.cs

@@ -1,26 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MoonSharp.Interpreter.Interop
-{
-	/// <summary>
-	/// Interface for proxy objects 
-	/// </summary>
-	/// <typeparam name="TProxy">The type of the proxy.</typeparam>
-	/// <typeparam name="TTarget">The type of the target.</typeparam>
-	public interface IProxyHandler<TProxy, TTarget>
-		where TProxy : class
-		where TTarget : class
-	{
-		/// <summary>
-		/// Takes an instance of a target object and returns a proxy object wrapping it
-		/// </summary>
-		TProxy ProxyWrap(TTarget target);
-		/// <summary>
-		/// Takes an instance of a proxy object and returns the real object behind it
-		/// </summary>
-		TTarget ProxyUnwrap(TProxy proxy);
-	}
-}

+ 0 - 29
src/MoonSharp.Interpreter/Interop/StandardDescriptors/EnumDescriptor.cs

@@ -1,29 +0,0 @@
-//using System;
-//using System.Collections.Generic;
-//using System.Linq;
-//using System.Text;
-
-//namespace MoonSharp.Interpreter.Interop.StandardDescriptors
-//{
-//	public sealed class EnumDescriptor : DispatchingUserDataDescriptor
-//	{
-//		public EnumDescriptor(Type enumType)
-//			: base(enumType)
-//		{
-//			FillEnumMembers();
-//		}
-
-//		private void FillEnumMembers()
-//		{
-//			foreach (string name in Enum.GetNames(enumType))
-//			{
-
-//			}
-
-//		}
-
-
-
-
-//	}
-//}

+ 127 - 0
src/MoonSharp.Interpreter/Interop/StandardDescriptors/ProxyUserDataDescriptor.cs

@@ -0,0 +1,127 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MoonSharp.Interpreter.Interop
+{
+	/// <summary>
+	/// Data descriptor used for proxy objects
+	/// </summary>
+	public sealed class ProxyUserDataDescriptor : IUserDataDescriptor
+	{
+		StandardUserDataDescriptor m_ProxyDescriptor;
+		IProxyFactory m_ProxyFactory;
+
+		internal ProxyUserDataDescriptor(IProxyFactory proxyFactory, InteropAccessMode accessMode = InteropAccessMode.Default, string friendlyName = null)
+		{
+			m_ProxyFactory = proxyFactory;
+			Name = friendlyName ?? (proxyFactory.TargetType.Name + "::proxy");
+			m_ProxyDescriptor = new StandardUserDataDescriptor(proxyFactory.ProxyType, accessMode, friendlyName + "::proxied");
+		}
+
+		/// <summary>
+		/// Gets the descriptor which describes the proxy object
+		/// </summary>
+		public IUserDataDescriptor InnerDescriptor
+		{
+			get { return m_ProxyDescriptor; }
+		}
+
+		/// <summary>
+		/// Gets the name of the descriptor (usually, the name of the type described).
+		/// </summary>
+		public string Name
+		{
+			get;
+			private set; 
+		}
+
+		/// <summary>
+		/// Gets the type this descriptor refers to
+		/// </summary>
+		public Type Type
+		{
+			get { return m_ProxyFactory.TargetType; }
+		}
+
+		/// <summary>
+		/// Proxies the specified object.
+		/// </summary>
+		/// <param name="obj">The object.</param>
+		/// <returns></returns>
+		private object Proxy(object obj)
+		{
+			return obj != null ? m_ProxyFactory.CreateProxyObject(obj) : null;
+		}
+
+		/// <summary>
+		/// Performs an "index" "get" operation.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="index">The index.</param>
+		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
+		/// <returns></returns>
+		public DynValue Index(Script script, object obj, DynValue index, bool isDirectIndexing)
+		{
+			return m_ProxyDescriptor.Index(script, Proxy(obj), index, isDirectIndexing);
+		}
+
+		/// <summary>
+		/// Performs an "index" "set" operation.
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="index">The index.</param>
+		/// <param name="value">The value to be set</param>
+		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
+		/// <returns></returns>
+		public bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isDirectIndexing)
+		{
+			return m_ProxyDescriptor.SetIndex(script, Proxy(obj), index, value, isDirectIndexing);
+		}
+
+		/// <summary>
+		/// Converts this userdata to string
+		/// </summary>
+		/// <param name="obj">The object.</param>
+		/// <returns></returns>
+		public string AsString(object obj)
+		{
+			return m_ProxyDescriptor.AsString(Proxy(obj));
+		}
+
+		/// <summary>
+		/// Gets a "meta" operation on this userdata. If a descriptor does not support this functionality,
+		/// it should return "null" (not a nil).
+		/// These standard metamethods can be supported (the return value should be a function accepting the
+		/// classic parameters of the corresponding metamethod):
+		/// __add, __sub, __mul, __div, __div, __pow, __unm, __eq, __lt, __le, __lt, __len, __concat,
+		/// __pairs, __ipairs, __iterator, __call
+		/// These standard metamethods are supported through other calls for efficiency:
+		/// __index, __newindex, __tostring
+		/// </summary>
+		/// <param name="script">The script originating the request</param>
+		/// <param name="obj">The object (null if a static request is done)</param>
+		/// <param name="metaname">The name of the metamember.</param>
+		/// <returns></returns>
+		public DynValue MetaIndex(Script script, object obj, string metaname)
+		{
+			return m_ProxyDescriptor.MetaIndex(script, Proxy(obj), metaname);
+		}
+
+		/// <summary>
+		/// Determines whether the specified object is compatible with the specified type.
+		/// Unless a very specific behaviour is needed, the correct implementation is a
+		/// simple " return type.IsInstanceOfType(obj); "
+		/// </summary>
+		/// <param name="type">The type.</param>
+		/// <param name="obj">The object.</param>
+		/// <returns></returns>
+		public bool IsTypeCompatible(Type type, object obj)
+		{
+			return type.IsInstanceOfType(obj);
+		}
+	}
+}

+ 38 - 12
src/MoonSharp.Interpreter/Interop/UserDataRegistries/TypeDescriptorRegistry.cs

@@ -111,6 +111,19 @@ namespace MoonSharp.Interpreter.Interop.UserDataRegistries
 		/// </summary>
 		internal static InteropRegistrationPolicy RegistrationPolicy { get; set; }
 
+		/// <summary>
+		/// Registers a proxy type.
+		/// </summary>
+		/// <param name="proxyFactory">The proxy factory.</param>
+		/// <param name="accessMode">The access mode.</param>
+		/// <param name="friendlyName">Name of the friendly.</param>
+		/// <returns></returns>
+		internal static IUserDataDescriptor RegisterProxyType_Impl(IProxyFactory proxyFactory, InteropAccessMode accessMode, string friendlyName)
+		{
+			accessMode = ResolveDefaultAccessModeForType(accessMode, proxyFactory.ProxyType);
+			return RegisterType_Impl(proxyFactory.TargetType, accessMode, friendlyName, new ProxyUserDataDescriptor(proxyFactory, accessMode, friendlyName));
+		}
+
 
 		/// <summary>
 		/// Registers a type
@@ -122,18 +135,7 @@ namespace MoonSharp.Interpreter.Interop.UserDataRegistries
 		/// <returns></returns>
 		internal static IUserDataDescriptor RegisterType_Impl(Type type, InteropAccessMode accessMode, string friendlyName, IUserDataDescriptor descriptor)
 		{
-			if (accessMode == InteropAccessMode.Default)
-			{
-				MoonSharpUserDataAttribute attr = type.GetCustomAttributes(true).OfType<MoonSharpUserDataAttribute>()
-					.SingleOrDefault();
-
-				if (attr != null)
-					accessMode = attr.AccessMode;
-			}
-
-
-			if (accessMode == InteropAccessMode.Default)
-				accessMode = s_DefaultAccessMode;
+			accessMode = ResolveDefaultAccessModeForType(accessMode, type);
 
 			lock (s_Lock)
 			{
@@ -185,6 +187,30 @@ namespace MoonSharp.Interpreter.Interop.UserDataRegistries
 			}
 		}
 
+		/// <summary>
+		/// Resolves the default type of the access mode for the given type
+		/// </summary>
+		/// <param name="accessMode">The access mode.</param>
+		/// <param name="type">The type.</param>
+		/// <returns></returns>
+		internal static InteropAccessMode ResolveDefaultAccessModeForType(InteropAccessMode accessMode, Type type)
+		{
+			if (accessMode == InteropAccessMode.Default)
+			{
+				MoonSharpUserDataAttribute attr = type.GetCustomAttributes(true).OfType<MoonSharpUserDataAttribute>()
+					.SingleOrDefault();
+
+				if (attr != null)
+					accessMode = attr.AccessMode;
+			}
+
+
+			if (accessMode == InteropAccessMode.Default)
+				accessMode = s_DefaultAccessMode;
+
+			return accessMode;
+		}
+
 
 
 		/// <summary>

+ 2 - 0
src/MoonSharp.Interpreter/Loaders/UnityAssetsScriptLoader.cs

@@ -72,7 +72,9 @@ namespace MoonSharp.Interpreter.Loaders
 			}
 			catch (Exception ex)
 			{
+#if !PCL
 				Console.WriteLine("Error initializing UnityScriptLoader : {0}", ex);
+#endif
 			}
 		}
 

+ 3 - 3
src/MoonSharp.Interpreter/MoonSharp.Interpreter.net35-client.csproj

@@ -156,9 +156,9 @@
     <Compile Include="Interop\BasicDescriptors\DispatchingUserDataDescriptor.cs" />
     <Compile Include="Interop\IGeneratorUserDataDescriptor.cs" />
     <Compile Include="Interop\PropertyTableAssigner.cs" />
-    <Compile Include="Interop\ProxyObjects\DelegateProxyObjectFactory.cs" />
-    <Compile Include="Interop\ProxyObjects\IScriptProxyObjectFactory.cs" />
-    <Compile Include="Interop\StandardDescriptors\EnumDescriptor.cs" />
+    <Compile Include="Interop\ProxyObjects\DelegateProxyFactory.cs" />
+    <Compile Include="Interop\ProxyObjects\IProxyFactory.cs" />
+    <Compile Include="Interop\StandardDescriptors\ProxyUserDataDescriptor.cs" />
     <Compile Include="Interop\StandardDescriptors\MemberDescriptors\ObjectCallbackMemberDescriptor.cs" />
     <Compile Include="Interop\StandardDescriptors\MemberDescriptors\FunctionMemberDescriptorBase.cs" />
     <Compile Include="Interop\StandardDescriptors\StandardEnumUserDataDescriptor.cs" />

+ 14 - 2
src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.net40-client/MoonSharp.Interpreter.net40-client.csproj

@@ -131,6 +131,12 @@
     <Compile Include="..\..\Interop\Attributes\MoonSharpUserDataMetamethodAttribute.cs">
       <Link>MoonSharpUserDataMetamethodAttribute.cs</Link>
     </Compile>
+    <Compile Include="..\..\Interop\Attributes\MoonSharpHideMemberAttribute.cs">
+      <Link>MoonSharpHideMemberAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Interop\Attributes\MoonSharpHiddenAttribute.cs">
+      <Link>MoonSharpHiddenAttribute.cs</Link>
+    </Compile>
     <Compile Include="..\..\Interop\BasicDescriptors\IMemberDescriptor.cs">
       <Link>IMemberDescriptor.cs</Link>
     </Compile>
@@ -176,8 +182,14 @@
     <Compile Include="..\..\Interop\PropertyTableAssigner.cs">
       <Link>PropertyTableAssigner.cs</Link>
     </Compile>
-    <Compile Include="..\..\Interop\StandardDescriptors\EnumDescriptor.cs">
-      <Link>EnumDescriptor.cs</Link>
+    <Compile Include="..\..\Interop\ProxyObjects\DelegateProxyFactory.cs">
+      <Link>DelegateProxyFactory.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Interop\ProxyObjects\IProxyFactory.cs">
+      <Link>IProxyFactory.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Interop\StandardDescriptors\ProxyUserDataDescriptor.cs">
+      <Link>ProxyUserDataDescriptor.cs</Link>
     </Compile>
     <Compile Include="..\..\Interop\StandardDescriptors\MemberDescriptors\ObjectCallbackMemberDescriptor.cs">
       <Link>ObjectCallbackMemberDescriptor.cs</Link>

+ 14 - 2
src/MoonSharp.Interpreter/_Projects/MoonSharp.Interpreter.portable40/MoonSharp.Interpreter.portable40.csproj

@@ -128,6 +128,12 @@
     <Compile Include="..\..\Interop\Attributes\MoonSharpUserDataMetamethodAttribute.cs">
       <Link>MoonSharpUserDataMetamethodAttribute.cs</Link>
     </Compile>
+    <Compile Include="..\..\Interop\Attributes\MoonSharpHideMemberAttribute.cs">
+      <Link>MoonSharpHideMemberAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Interop\Attributes\MoonSharpHiddenAttribute.cs">
+      <Link>MoonSharpHiddenAttribute.cs</Link>
+    </Compile>
     <Compile Include="..\..\Interop\BasicDescriptors\IMemberDescriptor.cs">
       <Link>IMemberDescriptor.cs</Link>
     </Compile>
@@ -173,8 +179,14 @@
     <Compile Include="..\..\Interop\PropertyTableAssigner.cs">
       <Link>PropertyTableAssigner.cs</Link>
     </Compile>
-    <Compile Include="..\..\Interop\StandardDescriptors\EnumDescriptor.cs">
-      <Link>EnumDescriptor.cs</Link>
+    <Compile Include="..\..\Interop\ProxyObjects\DelegateProxyFactory.cs">
+      <Link>DelegateProxyFactory.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Interop\ProxyObjects\IProxyFactory.cs">
+      <Link>IProxyFactory.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Interop\StandardDescriptors\ProxyUserDataDescriptor.cs">
+      <Link>ProxyUserDataDescriptor.cs</Link>
     </Compile>
     <Compile Include="..\..\Interop\StandardDescriptors\MemberDescriptors\ObjectCallbackMemberDescriptor.cs">
       <Link>ObjectCallbackMemberDescriptor.cs</Link>