diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-02-26 12:04:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-02-26 12:04:06 +0300 |
commit | c785532becca59aa2d1b3ae67784b7ac2b733ec2 (patch) | |
tree | 307355d1dec68595375840ec9546f1e9c8c7a535 /source/gameengine/Expressions/PyObjectPlus.cpp | |
parent | 936a6eeda87bfd36ada735e5edac06f161a5de25 (diff) |
Py BGE API
Python dir(ob) for game types now includes attributes names,
* Use "__dict__" rather then "__methods__" attribute to be Python 3.0 compatible
* Added _getattr_dict() for getting the method and attribute names from a PyObject, rather then building it in the macro.
* Added place holder *::Attribute array, needed for the _getattr_up macro.
Diffstat (limited to 'source/gameengine/Expressions/PyObjectPlus.cpp')
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index e04b42ee9cc..1bead0a7664 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -707,5 +707,35 @@ PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA Py_RETURN_FALSE; } +/* Utility function called by the macro _getattr_up() + * for getting ob.__dict__() values from our PyObject + * this is used by python for doing dir() on an object, so its good + * if we return a list of attributes and methods. + * + * 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) +{ + if(pydict==NULL) { /* incase calling __dict__ on the parent of this object raised an error */ + PyErr_Clear(); + pydict = PyDict_New(); + } + + if(meth) { + for (; meth->ml_name != NULL; meth++) { + PyDict_SetItemString(pydict, meth->ml_name, Py_None); + } + } + + if(attrdef) { + for (; attrdef->m_name != NULL; attrdef++) { + PyDict_SetItemString(pydict, attrdef->m_name, Py_None); + } + } + + return pydict; +} + #endif //NO_EXP_PYTHON_EMBEDDING |