diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-03-23 00:36:48 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-03-23 00:36:48 +0300 |
commit | e3d0dfc9eb3c9b20e0915256eab66ed23a34633f (patch) | |
tree | 5f6614c634f2654393a7de7817254e91d2848d8f /source/gameengine/Expressions/PyObjectPlus.cpp | |
parent | fa765a554c6883364dc24c286dd5b630ce5dcfe6 (diff) |
BGE API cleanup: add support for attribute set/get through functions only.
Diffstat (limited to 'source/gameengine/Expressions/PyObjectPlus.cpp')
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 1bead0a7664..494a848be74 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -143,6 +143,13 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel // fake attribute, ignore return NULL; } + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) + { + // the attribute has no field correspondance, handover processing to function. + if (attrdef->m_getFunction == NULL) + return NULL; + return (*attrdef->m_getFunction)(self, attrdef); + } char *ptr = reinterpret_cast<char*>(self)+attrdef->m_offset; if (attrdef->m_length > 1) { @@ -270,6 +277,13 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } switch (attrdef->m_type) { + case KX_PYATTRIBUTE_TYPE_FUNCTION: + if (attrdef->m_setFunction == NULL) + { + PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); + return 1; + } + return (*attrdef->m_setFunction)(self, attrdef, value); case KX_PYATTRIBUTE_TYPE_BOOL: bufferSize = sizeof(bool); break; @@ -419,9 +433,9 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } } // no error, call check function if any - if (attrdef->m_function != NULL) + if (attrdef->m_checkFunction != NULL) { - if ((*attrdef->m_function)(self, attrdef) != 0) + if ((*attrdef->m_checkFunction)(self, attrdef) != 0) { // post check returned an error, restore values UNDO_AND_ERROR: @@ -439,8 +453,16 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } else // simple attribute value { - - if (attrdef->m_function != NULL) + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) + { + if (attrdef->m_setFunction == NULL) + { + PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); + return 1; + } + return (*attrdef->m_setFunction)(self, attrdef, value); + } + if (attrdef->m_checkFunction != NULL) { // post check function is provided, prepare undo buffer sourceBuffer = ptr; @@ -628,9 +650,9 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } } // check if post processing is needed - if (attrdef->m_function != NULL) + if (attrdef->m_checkFunction != NULL) { - if ((*attrdef->m_function)(self, attrdef) != 0) + if ((*attrdef->m_checkFunction)(self, attrdef) != 0) { // restore value RESTORE_AND_ERROR: |