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:
Diffstat (limited to 'source/gameengine/Expressions/ListValue.cpp')
-rw-r--r--source/gameengine/Expressions/ListValue.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp
index d0aec645468..16b4fbef6b7 100644
--- a/source/gameengine/Expressions/ListValue.cpp
+++ b/source/gameengine/Expressions/ListValue.cpp
@@ -233,6 +233,7 @@ PyMethodDef CListValue::Methods[] = {
{"reverse", (PyCFunction)CListValue::sPyreverse,METH_NOARGS},
{"index", (PyCFunction)CListValue::sPyindex,METH_O},
{"count", (PyCFunction)CListValue::sPycount,METH_O},
+ {"from_id", (PyCFunction)CListValue::sPyfrom_id,METH_O},
{NULL,NULL} //Sentinel
};
@@ -502,6 +503,34 @@ PyObject* CListValue::Pycount(PyObject* self, PyObject* value)
+PyObject* CListValue::Pyfrom_id(PyObject* self, PyObject* value)
+{
+#if SIZEOF_VOID_P <= SIZEOF_LONG
+#define BGE_ID_TYPE unsigned long
+ BGE_ID_TYPE id= PyLong_AsUnsignedLong(value);
+#else
+#define BGE_ID_TYPE unsigned long long
+ BGE_ID_TYPE id= PyLong_FromUnsignedLongLong(value);
+#endif
+
+ if (id==-1 && PyErr_Occurred())
+ return NULL;
+
+ int numelem = GetCount();
+ for (int i=0;i<numelem;i++)
+ {
+ if (reinterpret_cast<BGE_ID_TYPE>(static_cast<PyObject*>(m_pValueArray[i])) == id)
+ return GetValue(i);
+
+ }
+ PyErr_SetString(PyExc_IndexError, "from_id(#), id not found in CValueList");
+ return NULL;
+
+}
+
+#undef BGE_ID_TYPE
+
+
/* ---------------------------------------------------------------------
* Some stuff taken from the header
* --------------------------------------------------------------------- */