[PyObjC-svn] r2054 - trunk/pyobjc/pyobjc-core/Modules/objc

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Thu Feb  5 09:59:59 2009
New Revision: 2054

Log:
Add name to representation of a function object.


Modified:
   trunk/pyobjc/pyobjc-core/Modules/objc/function.m

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/function.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/function.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/function.m	Thu Feb  5 09:59:59 2009
@@ -23,6 +23,8 @@
 	PyObject* module;
 } func_object;
 
+
+
 PyDoc_STRVAR(func_metadata_doc, "Return a dict that describes the metadata for this function.");
 static PyObject* func_metadata(PyObject* self)
 {
@@ -72,6 +74,32 @@
 	}
 };
 
+static PyObject* func_repr(PyObject* _self)
+{
+	func_object* self = (func_object*)_self;
+	char buf[128];
+
+	if (self->name == NULL) {
+		snprintf(buf, 128, "<objc.function object at %p>", self);
+	} else if (PyString_Check(self->name)) {
+		snprintf(buf, 128, "<objc.function '%s' at %p>", PyString_AsString(self->name), self);
+	} else {
+		PyObject* name_repr = PyObject_Repr(self->name);
+		if (name_repr == NULL) {
+			return NULL;
+		}
+		if (!PyString_Check(name_repr)) {
+			snprintf(buf, 128, "<objc.function object at %p>", self);
+		} else {
+			snprintf(buf, 128, "<objc.function '%s' at %p>", PyString_AsString(name_repr), self);
+		}
+		Py_DECREF(name_repr);
+	}
+	return PyString_FromString(buf);
+}
+
+
+
 static PyObject* 
 func_call(PyObject* s, PyObject* args, PyObject* kwds)
 {
@@ -252,7 +280,7 @@
 	0,					/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
-	0,					/* tp_repr */
+	func_repr,				/* tp_repr */
 	0,					/* tp_as_number */
 	0,					/* tp_as_sequence */
 	0,					/* tp_as_mapping */

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.