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-07 15:06:35 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-07 15:06:35 +0400
commit5d64dd019e7e8150db40505097d1b4048f4e0153 (patch)
tree65d3ac2f7d7d8a9e3aad5ba5331c43a5d1fca358 /source/gameengine/Expressions/PyObjectPlus.h
parentc054ea02039e9209095108c1b1f42250a7e85d8f (diff)
BGE Python API
Use each types dictionary to store attributes PyAttributeDef's so it uses pythons hash lookup (which it was already doing for methods) rather then doing a string lookup on the array each time. This also means attributes can be found in the type without having to do a dir() on the instance.
Diffstat (limited to 'source/gameengine/Expressions/PyObjectPlus.h')
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.h48
1 files changed, 38 insertions, 10 deletions
diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h
index f178d03e131..41bf72964ce 100644
--- a/source/gameengine/Expressions/PyObjectPlus.h
+++ b/source/gameengine/Expressions/PyObjectPlus.h
@@ -99,20 +99,42 @@ static inline void Py_Fatal(const char *M) {
// to be properly passed up the hierarchy.
#define py_getattro_up(Parent) \
- PyObject *rvalue; \
+ \
PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
\
- if (descr == NULL) { \
- PyErr_Clear(); \
- rvalue = Parent::py_getattro(attr); \
+ if(descr) { \
+ if (PyCObject_Check(descr)) { \
+ return py_get_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr)); \
+ } else { \
+ return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \
+ } \
} else { \
- rvalue= PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \
- } \
- \
- if (strcmp(PyString_AsString(attr), "__dict__")==0) {\
- rvalue = py_getattr_dict(rvalue, Methods, Attributes); \
+ PyErr_Clear(); \
+ PyObject *rvalue= Parent::py_getattro(attr); \
+ \
+ if (strcmp(PyString_AsString(attr), "__dict__")==0) { \
+ return py_getattr_dict(rvalue, Methods, Attributes); \
+ } \
+ \
+ return rvalue; \
} \
- return rvalue; \
+ return NULL;
+
+
+#define py_setattro_up(Parent) \
+ PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
+ \
+ if(descr) { \
+ if (PyCObject_Check(descr)) { \
+ return py_set_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr), value); \
+ } else { \
+ PyErr_Format(PyExc_AttributeError, "\"%s\" cannot be set", PyString_AsString(attr)); \
+ return -1; \
+ } \
+ } else { \
+ PyErr_Clear(); \
+ return Parent::py_setattro(attr, value); \
+ }
/**
@@ -376,8 +398,14 @@ public:
{
return ((PyObjectPlus*) PyObj)->py_getattro(attr);
}
+
+ static PyObject* py_get_attrdef(void *self, const PyAttributeDef *attrdef);
+ static int py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value);
+
+#if 0
static PyObject *py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr);
static int py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value);
+#endif
virtual int py_delattro(PyObject *attr);
virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method