From e80b37cd751260232678ebd550aa5a0f2226b693 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 2 Sep 2009 20:46:28 +0000 Subject: * KX_PythonSeq - comparisons work again. eg. act1.sensors == act2.sensors, had to copy Py_CmpToRich inline grr!, mailed python-dev about this. * Shift-Click on states in the logic UI works again. * New Logic Space has all the view options pressed. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 38 ++++++++++++++++++++++++++++++ source/gameengine/Ketsji/KX_PythonSeq.cpp | 20 ++++++++++++---- 2 files changed, 54 insertions(+), 4 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 67ab67814b2..667b4cd5d89 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -2018,4 +2018,42 @@ void resetGamePythonPath() } +/* Copied from pythons 3's Object.c + * also in blenders bpy_uitl.c, mailed the python-dev + * list about enabling something like this again for py3 */ +PyObject * +Py_CmpToRich(int op, int cmp) +{ + PyObject *res; + int ok; + + if (PyErr_Occurred()) + return NULL; + switch (op) { + case Py_LT: + ok = cmp < 0; + break; + case Py_LE: + ok = cmp <= 0; + break; + case Py_EQ: + ok = cmp == 0; + break; + case Py_NE: + ok = cmp != 0; + break; + case Py_GT: + ok = cmp > 0; + break; + case Py_GE: + ok = cmp >= 0; + break; + default: + PyErr_BadArgument(); + return NULL; + } + res = ok ? Py_True : Py_False; + Py_INCREF(res); + return res; +} diff --git a/source/gameengine/Ketsji/KX_PythonSeq.cpp b/source/gameengine/Ketsji/KX_PythonSeq.cpp index 1098dc03b62..165a85e2c14 100644 --- a/source/gameengine/Ketsji/KX_PythonSeq.cpp +++ b/source/gameengine/Ketsji/KX_PythonSeq.cpp @@ -345,6 +345,19 @@ static int KX_PythonSeq_compare( KX_PythonSeq * a, KX_PythonSeq * b ) /* TODO - return ( a->type == b->type && a->base == b->base) ? 0 : -1; } +extern PyObject *Py_CmpToRich(int op, int cmp); + +static PyObject *KX_PythonSeq_richcmp(PyObject *a, PyObject *b, int op) +{ + int cmp_result= -1; /* assume false */ + + if(BPy_KX_PythonSeq_Check(a) && BPy_KX_PythonSeq_Check(b)) { + cmp_result= KX_PythonSeq_compare((KX_PythonSeq *)a, (KX_PythonSeq *)b); + } + + return Py_CmpToRich(op, cmp_result); +} + /* * repr function * convert to a list and get its string value @@ -374,8 +387,7 @@ PyTypeObject KX_PythonSeq_Type = { NULL, /* printfunc tp_print; */ NULL, /* getattrfunc tp_getattr; */ NULL, /* setattrfunc tp_setattr; */ - /* TODO, richcmp */ - NULL, /* ( cmpfunc ) KX_PythonSeq_compare, // cmpfunc tp_compare; */ + NULL, /* cmpfunc tp_compare; */ ( reprfunc ) KX_PythonSeq_repr, /* reprfunc tp_repr; */ /* Method suites for standard classes */ @@ -401,14 +413,14 @@ PyTypeObject KX_PythonSeq_Type = { NULL, /* char *tp_doc; Documentation string */ /*** Assigned meaning in release 2.0 ***/ /* call function for all accessible objects */ - NULL, /* traverseproc tp_traverse; */ + NULL, /* traverseproc tp_traverse; */ /* delete references to contained objects */ NULL, /* inquiry tp_clear; */ /*** Assigned meaning in release 2.1 ***/ /*** rich comparisons ***/ - NULL, /* richcmpfunc tp_richcompare; */ + (richcmpfunc)KX_PythonSeq_richcmp, /* richcmpfunc tp_richcompare; */ /*** weak reference enabler ***/ 0, /* long tp_weaklistoffset; */ -- cgit v1.2.3