diff dstep/objc/bridge/Capsule.d @ 25:b9de51448c6b

Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
author Jacob Carlborg <doob@me.com>
date Tue, 06 Apr 2010 11:37:27 +0200
parents ab33fc0c3fc1
children
line wrap: on
line diff
--- a/dstep/objc/bridge/Capsule.d	Wed Feb 10 19:24:32 2010 +0100
+++ b/dstep/objc/bridge/Capsule.d	Tue Apr 06 11:37:27 2010 +0200
@@ -20,6 +20,7 @@
 	import std.math : log2;
 }
 
+import dstep.internal.Reflection;
 import dstep.internal.String;
 import dstep.objc.bridge.Bridge;
 import dstep.objc.bridge.Type;
@@ -204,11 +205,11 @@
 {
 	static if (needsEncapsulation!(T))
 	{		
-		static if (hasIdConstructor!(T))
+		static if (is(T : ObjcWrapper))
 		{
 			T instance = cast(T) Bridge.getDObject(value);
 			
-			return instance ? instance : new T(value);
+			return instance ? instance : newWrapper!(T)(value);
 		}
 		
 		else
@@ -219,6 +220,15 @@
 		return value;
 }
 
+private T newWrapper (T) (ObjcType!(T) value)
+{
+	auto wrapper = cast(ObjcWrapper) newInstance(T.classinfo);
+	setValueOfField!("objcObject_")(wrapper, value);
+	Bridge.setDObject(wrapper, value);
+	
+	return cast(T) wrapper;
+}
+
 private id encapsuleString (string str)
 {
 	enum { NSUTF8StringEncoding = 4 }