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:
authorCampbell Barton <ideasman42@gmail.com>2009-04-12 18:22:51 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-12 18:22:51 +0400
commit332032fb9925091da49efa2e9c3653bdb3e68cba (patch)
treeb482f26a2fe9fa953fbc501ddf39cb927ac0c2a6 /source/gameengine/Expressions/Value.cpp
parentee24c829b56ebddb47ae2bcfe30db5d857610450 (diff)
BGE Python API
Support for assigning any Type to a KX_GameObject so you can do... gameOb.follow = otherGameOb gameOb[otherGameOb] = distanceTo gameOb["path"] = [(x,y,x), (x,y,x)] del gameOb[mesh] * types that cannot be converted into CValue types are written into the KX_GameObject dict * the KX_GameObject dict is only initialized when needed * Python properties in this dict cannot be accessed by logic bricks * dir(ob) and ob.getPropertyNames() return items from both CValue and Py dictionary properties. Also found that CType was converting python lists to CType Lists but very buggy, would crash after printing the list most times. Use python lists instead since logic bricks dont deal with lists.
Diffstat (limited to 'source/gameengine/Expressions/Value.cpp')
-rw-r--r--source/gameengine/Expressions/Value.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp
index f1e367d6e59..b8b7a05aa64 100644
--- a/source/gameengine/Expressions/Value.cpp
+++ b/source/gameengine/Expressions/Value.cpp
@@ -719,7 +719,8 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj)
{
CValue* vallie = NULL;
-
+ /* refcounting is broking here! - this crashes anyway, just store a python list for KX_GameObject */
+#if 0
if (PyList_Check(pyobj))
{
CListValue* listval = new CListValue();
@@ -750,6 +751,7 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj)
}
} else
+#endif
if (PyFloat_Check(pyobj))
{
vallie = new CFloatValue( (float)PyFloat_AsDouble(pyobj) );
@@ -790,21 +792,34 @@ int CValue::py_delattro(PyObject *attr)
int CValue::py_setattro(PyObject *attr, PyObject* pyobj)
{
+ char *attr_str= PyString_AsString(attr);
+ CValue* oldprop = GetProperty(attr_str);
+
CValue* vallie = ConvertPythonToValue(pyobj);
if (vallie)
{
- char *attr_str= PyString_AsString(attr);
- CValue* oldprop = GetProperty(attr_str);
-
if (oldprop)
oldprop->SetValue(vallie);
else
SetProperty(attr_str, vallie);
vallie->Release();
- } else
- {
- return PY_SET_ATTR_FAIL; /* ConvertPythonToValue sets the error message */
+ }
+ else {
+ // ConvertPythonToValue sets the error message
+ // must return missing so KX_GameObect knows this
+ // attribute was not a function or bult in attribute,
+ //
+ // CValue attributes override internal attributes
+ // so if it exists as a CValue attribute already,
+ // assume your trying to set it to a differnt CValue attribute
+ // otherwise return PY_SET_ATTR_MISSING so children
+ // classes know they can set it without conflict
+
+ if (GetProperty(attr_str))
+ return PY_SET_ATTR_COERCE_FAIL; /* failed to set an existing attribute */
+ else
+ return PY_SET_ATTR_MISSING; /* allow the KX_GameObject dict to set */
}
//PyObjectPlus::py_setattro(attr,value);