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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-02-19 10:01:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-02-19 10:01:49 +0300
commit92d4ef0939c82e5654f899fe8e55e7a2cccbf6a0 (patch)
treef0ed1ad06dfc40e5b4b61ebe2bb3facff57bcb36 /source
parent7d2582de09935c7050665a738eaca9097f3d0870 (diff)
Accept negative indices's for ListValues
scene.getObjectList()[-1] works like a python sequence. removed some STR_String creation that was only used to do comparisons, in a simple expressions benchmark this made logic use 4% less overall.
Diffstat (limited to 'source')
-rw-r--r--source/gameengine/Expressions/InputParser.cpp19
-rw-r--r--source/gameengine/Expressions/ListValue.cpp10
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.cpp12
-rw-r--r--source/gameengine/Ketsji/KX_TouchSensor.cpp2
4 files changed, 23 insertions, 20 deletions
diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp
index 32a9de32e21..c3869d8f89b 100644
--- a/source/gameengine/Expressions/InputParser.cpp
+++ b/source/gameengine/Expressions/InputParser.cpp
@@ -272,32 +272,29 @@ void CParser::NextSym()
|| ((ch >= 'A') && (ch <= 'Z')))
{ // reserved word?
int start;
- STR_String funstr;
start = chcount;
CharRep();
GrabString(start);
- funstr = const_as_string;
- funstr.Upper();
- if (funstr == STR_String("SUM")) {
+ if (!strcasecmp(const_as_string, "SUM")) {
sym = sumsym;
}
- else if (funstr == STR_String("NOT")) {
+ else if (!strcasecmp(const_as_string, "NOT")) {
sym = opsym;
opkind = OPnot;
}
- else if (funstr == STR_String("AND")) {
+ else if (!strcasecmp(const_as_string, "AND")) {
sym = opsym; opkind = OPand;
}
- else if (funstr == STR_String("OR")) {
+ else if (!strcasecmp(const_as_string, "OR")) {
sym = opsym; opkind = OPor;
}
- else if (funstr == STR_String("IF")) {
+ else if (!strcasecmp(const_as_string, "IF"))
sym = ifsym;
- } else if (funstr == STR_String("WHOMADE")) {
+ else if (!strcasecmp(const_as_string, "WHOMADE"))
sym = whocodedsym;
- } else if (funstr == STR_String("FALSE")) {
+ else if (!strcasecmp(const_as_string, "FALSE")) {
sym = constsym; constkind = booltype; boolvalue = false;
- } else if (funstr == STR_String("TRUE")) {
+ } else if (!strcasecmp(const_as_string, "TRUE")) {
sym = constsym; constkind = booltype; boolvalue = true;
} else {
sym = idsym;
diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp
index 9ffdbb1223c..b7236afdee4 100644
--- a/source/gameengine/Expressions/ListValue.cpp
+++ b/source/gameengine/Expressions/ListValue.cpp
@@ -34,7 +34,12 @@ Py_ssize_t listvalue_bufferlen(PyObject* list)
PyObject* listvalue_buffer_item(PyObject* list,Py_ssize_t index)
{
- if (index >= 0 && index < ((CListValue*) list)->GetCount())
+ int count = ((CListValue*) list)->GetCount();
+
+ if (index < 0)
+ index = count+index;
+
+ if (index >= 0 && index < count)
{
PyObject* pyobj = ((CListValue*) list)->GetValue(index)->ConvertValueToPython();
if (pyobj)
@@ -64,8 +69,7 @@ PyObject* listvalue_mapping_subscript(PyObject* list,PyObject* pyindex)
}
PyObject *pyindex_str = PyObject_Repr(pyindex); /* new ref */
- STR_String index_str(PyString_AsString(pyindex_str));
- PyErr_Format(PyExc_KeyError, "'%s' not in list", index_str.Ptr());
+ PyErr_Format(PyExc_KeyError, "'%s' not in list", PyString_AsString(pyindex_str));
Py_DECREF(pyindex_str);
return NULL;
}
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp
index 8fd99c8d267..19f458b69a6 100644
--- a/source/gameengine/Expressions/PyObjectPlus.cpp
+++ b/source/gameengine/Expressions/PyObjectPlus.cpp
@@ -94,7 +94,7 @@ PyObjectPlus::PyObjectPlus(PyTypeObject *T) // constructor
* PyObjectPlus Methods -- Every class, even the abstract one should have a Methods
------------------------------*/
PyMethodDef PyObjectPlus::Methods[] = {
- {"isA", (PyCFunction) sPy_isA, METH_VARARGS},
+ {"isA", (PyCFunction) sPy_isA, METH_O},
{NULL, NULL} /* Sentinel */
};
@@ -688,19 +688,21 @@ bool PyObjectPlus::isA(const char *mytypename) // check typename of each parent
for (P = Ps[i=0]; P != NULL; P = Ps[i++])
{
- if (STR_String(P->tp_name) == STR_String(mytypename) )
+ if (strcmp(P->tp_name, mytypename)==0)
return true;
}
return false;
}
-PyObject *PyObjectPlus::Py_isA(PyObject *args) // Python wrapper for isA
+PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA
{
char *mytypename;
- if (!PyArg_ParseTuple(args, "s", &mytypename))
+ if (!PyString_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "expected a string");
return NULL;
- if(isA(mytypename))
+ }
+ if(isA(PyString_AsString(value)))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp
index 849972955af..0000d5793b6 100644
--- a/source/gameengine/Ketsji/KX_TouchSensor.cpp
+++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp
@@ -199,7 +199,7 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll
{
if (client_info->m_auxilary_info)
{
- found = (m_touchedpropname == STR_String((char*)client_info->m_auxilary_info));
+ found = (!strcmp(m_touchedpropname.Ptr(), (char*)client_info->m_auxilary_info));
}
} else
{