[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16063] trunk/blender/source/gameengine/ Expressions/Value.cpp: raise an error when assigning properties to a game object that cant be converted .
Campbell Barton
ideasman42 at gmail.com
Tue Aug 12 14:32:54 CEST 2008
Revision: 16063
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16063
Author: campbellbarton
Date: 2008-08-12 14:32:54 +0200 (Tue, 12 Aug 2008)
Log Message:
-----------
raise an error when assigning properties to a game object that cant be converted. also use python apis functions for converting floats and int types (faster then PyArg_Parse)
Modified Paths:
--------------
trunk/blender/source/gameengine/Expressions/Value.cpp
Modified: trunk/blender/source/gameengine/Expressions/Value.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/Value.cpp 2008-08-12 10:08:46 UTC (rev 16062)
+++ trunk/blender/source/gameengine/Expressions/Value.cpp 2008-08-12 12:32:54 UTC (rev 16063)
@@ -700,9 +700,7 @@
CValue* vallie = NULL;
- PyTypeObject* type = pyobj->ob_type;
-
- if (type == &PyList_Type)
+ if (PyList_Check(pyobj))
{
CListValue* listval = new CListValue();
bool error = false;
@@ -732,26 +730,25 @@
}
} else
- if (type == &PyFloat_Type)
+ if (PyFloat_Check(pyobj))
{
- float fl;
- PyArg_Parse(pyobj,"f",&fl);
- vallie = new CFloatValue(fl);
+ vallie = new CFloatValue( (float)PyFloat_AsDouble(pyobj) );
} else
- if (type==&PyInt_Type)
+ if (PyInt_Check(pyobj))
{
- int innie;
- PyArg_Parse(pyobj,"i",&innie);
- vallie = new CIntValue(innie);
+ vallie = new CIntValue( (int)PyInt_AS_LONG(pyobj) );
} else
-
- if (type==&PyString_Type)
+ if (PyString_Check(pyobj))
{
vallie = new CStringValue(PyString_AsString(pyobj),"");
} else
- if (type==&CValue::Type || type==&CListValue::Type)
+ if (pyobj->ob_type==&CValue::Type || pyobj->ob_type==&CListValue::Type)
{
vallie = ((CValue*) pyobj)->AddRef();
+ } else
+ {
+ /* return an error value from the caller */
+ PyErr_SetString(PyExc_TypeError, "This python value could not be assigned to a game engine property");
}
return vallie;
@@ -778,6 +775,9 @@
SetProperty(attr,vallie);
}
vallie->Release();
+ } else
+ {
+ return 1; /* ConvertPythonToValue sets the error message */
}
//PyObjectPlus::_setattr(attr,value);
More information about the Bf-blender-cvs
mailing list