Bug in KX_GameObject.get() and ListValue.get(), wasn't checking if the CValue derived objects could be converted to a PyObject.

so where foo is an int prop,
 gameOb.get("foo") == 0, would end up returning a CValue int proxy.

This is more a problem for KX_GameObject since ListValues with python access mostly don't contain ints, strings, floats.
This also wont break games from 2.48 since the .get() function wasn't available.
This commit is contained in:
Campbell Barton 2009-05-31 17:44:38 +00:00
parent 759d31d320
commit 8e882d0d61
2 changed files with 21 additions and 7 deletions

@ -77,8 +77,13 @@ PyObject* listvalue_mapping_subscript(PyObject* self, PyObject* pyindex)
if (PyString_Check(pyindex))
{
CValue *item = ((CListValue*) list)->FindValue(PyString_AsString(pyindex));
if (item)
return item->GetProxy();
if (item) {
PyObject* pyobj = item->ConvertValueToPython();
if(pyobj)
return pyobj;
else
return item->GetProxy();
}
}
else if (PyInt_Check(pyindex))
{
@ -575,9 +580,13 @@ PyObject* CListValue::Pyget(PyObject *args)
return NULL;
CValue *item = FindValue((const char *)key);
if (item)
return item->GetProxy();
if (item) {
PyObject* pyobj = item->ConvertValueToPython();
if (pyobj)
return pyobj;
else
return item->GetProxy();
}
Py_INCREF(def);
return def;
}

@ -2758,8 +2758,13 @@ PyObject* KX_GameObject::Pyget(PyObject *args)
if(PyString_Check(key)) {
CValue *item = GetProperty(PyString_AsString(key));
if (item)
return item->GetProxy();
if (item) {
ret = item->ConvertValueToPython();
if(ret)
return ret;
else
return item->GetProxy();
}
}
if (m_attr_dict && (ret=PyDict_GetItem(m_attr_dict, key))) {