Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-04 12:20:52 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-04 12:20:52 +0400
commita35a8f7a382e9f62834eaf355d448205665a07bc (patch)
tree022d6afbb70eb820678292cb7e584b88edec018f /source/gameengine/Expressions/PyObjectPlus.cpp
parentc31f806c99e14ef54a06ea90f0f66d4d1b2572a1 (diff)
- should fix compiling with older python versions (<2.5)
- made the isA() function accept python types as well as strings. - renamed _getattr_dict to py_getattr_dict
Diffstat (limited to 'source/gameengine/Expressions/PyObjectPlus.cpp')
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.cpp45
1 files changed, 25 insertions, 20 deletions
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp
index ed6932b414a..ac1871300d0 100644
--- a/source/gameengine/Expressions/PyObjectPlus.cpp
+++ b/source/gameengine/Expressions/PyObjectPlus.cpp
@@ -703,35 +703,40 @@ PyObject *PyObjectPlus::py_repr(void)
------------------------------*/
bool PyObjectPlus::isA(PyTypeObject *T) // if called with a Type, use "typename"
{
- return isA(T->tp_name);
+ int i;
+ PyParentObject P;
+ PyParentObject *Ps = GetParents();
+
+ for (P = Ps[i=0]; P != NULL; P = Ps[i++])
+ if (P==T)
+ return true;
+
+ return false;
}
bool PyObjectPlus::isA(const char *mytypename) // check typename of each parent
{
- int i;
- PyParentObject P;
- PyParentObject *Ps = GetParents();
+ int i;
+ PyParentObject P;
+ PyParentObject *Ps = GetParents();
- for (P = Ps[i=0]; P != NULL; P = Ps[i++])
- {
- if (strcmp(P->tp_name, mytypename)==0)
- return true;
- }
-
- return false;
+ for (P = Ps[i=0]; P != NULL; P = Ps[i++])
+ if (strcmp(P->tp_name, mytypename)==0)
+ return true;
+
+ return false;
}
PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA
{
- if (!PyString_Check(value)) {
- PyErr_SetString(PyExc_TypeError, "expected a string");
- return NULL;
- }
- if(isA(PyString_AsString(value)))
- Py_RETURN_TRUE;
- else
- Py_RETURN_FALSE;
+ if (PyType_Check(value)) {
+ return PyBool_FromLong(isA((PyTypeObject *)value));
+ } else if (PyString_Check(value)) {
+ return PyBool_FromLong(isA(PyString_AsString(value)));
+ }
+ PyErr_SetString(PyExc_TypeError, "expected a type or a string");
+ return NULL;
}
/* Utility function called by the macro py_getattro_up()
@@ -742,7 +747,7 @@ PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA
* Other then making dir() useful the value returned from __dict__() is not useful
* since every value is a Py_None
* */
-PyObject *_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef)
+PyObject *py_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef)
{
if(pydict==NULL) { /* incase calling __dict__ on the parent of this object raised an error */
PyErr_Clear();