diff dstep/objc/objc.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents c0cfd40362ee
children 6255d355d752
line wrap: on
line diff
--- a/dstep/objc/objc.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/objc/objc.d	Sun Jan 03 22:06:11 2010 +0100
@@ -34,8 +34,6 @@
 {
 	Class isa;
 	
-	
-	
 	// D Extensions:
 	
 	string getClassName ()
@@ -155,13 +153,13 @@
 
 	static if (dstep.internal.Version.X86 || X86_64)
 	{
-		R msgSend_fpret (R = id, ARGS...) (SEL op, ARGS args)
+		R msgSend_fpret (R, ARGS...) (SEL op, ARGS args)
 		{
 			version (X86_64)
-				static assert(!is(R == real), "dstep.objc.objc.objc_object.msgSend_fpret: Only real are legal return value for objc_msgSend_fpret");
+				static assert(is(R == real), "dstep.objc.objc.objc_object.msgSend_fpret: Only real are legal return value for objc_msgSend_fpret");
 			
 			else
-				static assert(!is(R == double) && !is(R == float), "dstep.objc.objc.objc_object.msgSend_fpret: Only double and float are legal return values for objc_msgSend_fpret");
+				static assert(is(R == double) || is(R == float), "dstep.objc.objc.objc_object.msgSend_fpret: Only double and float are legal return values for objc_msgSend_fpret");
 				
 			alias extern (C) R function (id, SEL, ARGS) fp;
 			return (cast(fp)&bindings.objc_msgSend_fpret)(this, op, args);
@@ -235,4 +233,107 @@
 	{
 		return bindings.sel_isMapped(this);
 	}
+}
+
+
+//D Extensions:
+
+struct objc
+{	
+	static string[] copyImageNames (out uint outCount)
+	{
+		string[] ret;
+		
+		char** result = bindings.objc_copyImageNames(&outCount);
+		ret.length = outCount;
+		
+		for (size_t i = 0; i < outCount; i++)
+			ret[i] = fromStringz(result[i]);
+		
+		return ret;
+	}
+	
+	alias bindings.objc_enumerationMutation objc_enumerationMutation;
+	alias bindings.objc_setForwardHandler objc_setForwardHandler;
+	alias bindings.objc_setMultithreaded objc_setMultithreaded;
+	
+	static id getClass (string name) ()
+	{
+		return bindings.objc_getClass(name.ptr);
+	}
+	
+	static id getMetaClass (string name) ()
+	{
+		return bindings.objc_getMetaClass(name.ptr);
+	}
+	
+	static id lookUpClass (string name) ()
+	{
+		return bindings.objc_lookUpClass(name.ptr);
+	}
+	
+	static id getRequiredClass (string name) ()
+	{
+		return bindings.objc_getRequiredClass(name.ptr);
+	}	
+	
+	static Class getFutureClass (string name) ()
+	{
+		return bindings.objc_getFutureClass(name.ptr);
+	}
+	
+	static string[] objc_copyClassNamesForImage (string image) (out uint outCount)
+	{
+		string[] ret;
+		
+		char** result = bindings.objc_copyClassNamesForImage(image.ptr, &outCount);
+		ret.length = outCount;
+		
+		for (size_t i = 0; i < outCount; i++)
+			ret[i] = fromStringz(result[i]);
+		
+		return ret;
+	}
+	
+	static Class objc_getOrigClass (string name) ()
+	{
+		return bindings.objc_getOrigClass(name.ptr);
+	}
+	
+	static Class allocateClassPair (string name) (Class superclass, size_t extraBytes)
+	{
+		return bindings.objc_allocateClassPair(superclass, name.ptr, extraBytes);
+	}
+	
+	alias bindings.objc_registerClassPair registerClassPair;
+	alias bindings.objc_disposeClassPair disposeClassPair;
+	alias bindings.objc_getClasses getClasses;
+	alias bindings.objc_addClass addClass;
+	alias bindings.class_createInstance createInstance;
+}
+
+struct property
+{
+	static string getName (objc_property_t* property)
+	{
+		return fromStringz(bindings.property_getName(property));
+	}
+
+	static string getAttributes (objc_property_t* property)
+	{
+		return fromStringz(bindings.property_getAttributes(property));
+	}
+}
+
+struct sel
+{	
+	static SEL getUid (string str) ()
+	{
+		return bindings.sel_getUid(str.ptr);
+	}
+	
+	static SEL registerName (string str) ()
+	{
+		return bindings.sel_registerName(str.ptr);
+	}
 }
\ No newline at end of file