[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15490] trunk/blender/source/gameengine/ Expressions/PyObjectPlus.h: bugfix - GameEngine PyObject methods did not all return when using dir(), because inherited methods were ignored, This made it incredibly annoying, not only having to search a C++ file to see what functions were available.

Campbell Barton ideasman42 at gmail.com
Tue Jul 8 19:57:31 CEST 2008


Revision: 15490
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15490
Author:   campbellbarton
Date:     2008-07-08 19:57:31 +0200 (Tue, 08 Jul 2008)

Log Message:
-----------
bugfix - GameEngine PyObject methods did not all return when using dir(), because inherited methods were ignored, This made it incredibly annoying, not only having to search a C++ file to see what functions were available. but looking up methods inherited from other C++ classes.
There is still no __members__ attribute so dir() wont work at all for attributes.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.h

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.h	2008-07-08 17:38:33 UTC (rev 15489)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.h	2008-07-08 17:57:31 UTC (rev 15490)
@@ -76,19 +76,37 @@
   virtual PyTypeObject *GetType(void) {return &Type;}; \
   virtual PyParentObject *GetParents(void) {return Parents;}
 
+
 								// This defines the _getattr_up macro
 								// which allows attribute and method calls
 								// to be properly passed up the hierarchy.
 #define _getattr_up(Parent) \
-  PyObject *rvalue = Py_FindMethod(Methods, this, const_cast<char*>(attr.ReadPtr())); \
-  if (rvalue == NULL) \
-    { \
+  PyObject *rvalue = NULL; \
+  if (attr=="__methods__") { \
+    PyObject *_attr_string = NULL; \
+    PyMethodDef *meth = Methods; \
+    rvalue = Parent::_getattr(attr); \
+    if (rvalue==NULL) { \
+    	PyErr_Clear(); \
+    	rvalue = PyList_New(0); \
+    } \
+    if (meth) { \
+      for (; meth->ml_name != NULL; meth++) { \
+        _attr_string = PyString_FromString(meth->ml_name); \
+		PyList_Append(rvalue, _attr_string); \
+		Py_DECREF(_attr_string); \
+	  } \
+	} \
+  } else { \
+    rvalue = Py_FindMethod(Methods, this, const_cast<char*>(attr.ReadPtr())); \
+    if (rvalue == NULL) { \
       PyErr_Clear(); \
-      return Parent::_getattr(attr); \
+      rvalue = Parent::_getattr(attr); \
     } \
-  else \
-    return rvalue 
+  } \
+  return rvalue; \
 
+
 /**
  * These macros are helpfull when embedding Python routines. The second
  * macro is one that also requires a documentation string





More information about the Bf-blender-cvs mailing list