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-06-28 15:22:26 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-06-28 15:22:26 +0400
commit6b9f3b5f5c8d918585e01461a6202ae3df2df621 (patch)
tree655463247dee5167a8b7063bc6705eac84701bed /source/gameengine/Expressions/Value.cpp
parent6998a0f47b673591f8561cda35d50e93979de32c (diff)
BGE Python API
Remove the last of the odd C++/python wrapper code from http://www.python.org/doc/PyCPP.html (~1998) * Use python subclasses rather then having fake subclassing through get/set attributes calling parent types. * PyObject getset arrays are created while initializing the types, converted from our own attribute arrays. This way python deals with subclasses and we dont have to define getattro or setattro functions for each type. * GameObjects and Scenes no longer have attribute access to properties. only dictionary style access - ob['prop'] * remove each class's get/set/dir functions. * remove isA() methods, can use PyObject_TypeCheck() in C and issubclass() in python. * remove Parents[] array for each C++ class, was only used for isA() and wasnt correct in quite a few cases. * remove PyTypeObject that was being passed as the last argument to each class (the parent classes too). TODO - * Light and VertexProxy need to be converted to using attributes. * memory for getset arrays is never freed, not that bad since its will only allocates once.
Diffstat (limited to 'source/gameengine/Expressions/Value.cpp')
-rw-r--r--source/gameengine/Expressions/Value.cpp99
1 files changed, 12 insertions, 87 deletions
diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp
index 61dabff510b..45eb15ecd08 100644
--- a/source/gameengine/Expressions/Value.cpp
+++ b/source/gameengine/Expressions/Value.cpp
@@ -54,15 +54,15 @@ PyTypeObject CValue::Type = {
py_base_repr,
0,
0,0,0,0,0,
- py_base_getattro,
- py_base_setattro,
- 0,0,0,0,0,0,0,0,0,
- Methods
-};
-
-PyParentObject CValue::Parents[] = {
- &CValue::Type,
- NULL
+ NULL, //py_base_getattro,
+ NULL, //py_base_setattro,
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ 0,0,0,0,0,0,0,
+ Methods,
+ 0,
+ 0,
+ &PyObjectPlus::Type
};
PyMethodDef CValue::Methods[] = {
@@ -100,8 +100,8 @@ std::vector<SmartCValueRef> gRefList;
//int gRefCountValue;
#endif
-CValue::CValue(PyTypeObject *T)
- : PyObjectPlus(T),
+CValue::CValue()
+ : PyObjectPlus(),
#else
CValue::CValue()
:
@@ -553,30 +553,6 @@ PyAttributeDef CValue::Attributes[] = {
{ NULL } //Sentinel
};
-
-PyObject* CValue::py_getattro(PyObject *attr)
-{
- char *attr_str= PyString_AsString(attr);
- CValue* resultattr = GetProperty(attr_str);
- if (resultattr)
- {
- /* only show the wanting here because python inspects for __class__ and KX_MeshProxy uses CValues name attr */
- ShowDeprecationWarning("val = ob.attr", "val = ob['attr']");
-
- PyObject* pyconvert = resultattr->ConvertValueToPython();
-
- if (pyconvert)
- return pyconvert;
- else
- return resultattr->GetProxy();
- }
- py_getattro_up(PyObjectPlus);
-}
-
-PyObject* CValue::py_getattro_dict() {
- py_getattro_dict_up(PyObjectPlus);
-}
-
PyObject * CValue::pyattr_get_name(void * self_v, const KX_PYATTRIBUTE_DEF * attrdef) {
CValue * self = static_cast<CValue *> (self_v);
return PyString_FromString(self->GetName());
@@ -637,7 +613,7 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj, const char *error_prefix)
} else
if (BGE_PROXY_CHECK_TYPE(pyobj)) /* Note, dont let these get assigned to GameObject props, must check elsewhere */
{
- if (BGE_PROXY_REF(pyobj) && (BGE_PROXY_REF(pyobj))->isA(&CValue::Type))
+ if (BGE_PROXY_REF(pyobj) && PyObject_TypeCheck(BGE_PROXY_REF(pyobj), &CValue::Type))
{
vallie = (static_cast<CValue *>(BGE_PROXY_REF(pyobj)))->AddRef();
} else {
@@ -656,57 +632,6 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj, const char *error_prefix)
}
-int CValue::py_delattro(PyObject *attr)
-{
- ShowDeprecationWarning("del ob.attr", "del ob['attr']");
-
- char *attr_str= PyString_AsString(attr);
- if (RemoveProperty(attr_str))
- return 0;
-
- PyErr_Format(PyExc_AttributeError, "attribute \"%s\" dosnt exist", attr_str);
- return PY_SET_ATTR_MISSING;
-}
-
-int CValue::py_setattro(PyObject *attr, PyObject* pyobj)
-{
- ShowDeprecationWarning("ob.attr = val", "ob['attr'] = val");
-
- char *attr_str= PyString_AsString(attr);
- CValue* oldprop = GetProperty(attr_str);
- CValue* vallie;
-
- /* Dissallow python to assign GameObjects, Scenes etc as values */
- if ((BGE_PROXY_CHECK_TYPE(pyobj)==0) && (vallie = ConvertPythonToValue(pyobj, "cvalue.attr = value: ")))
- {
- if (oldprop)
- oldprop->SetValue(vallie);
- else
- SetProperty(attr_str, vallie);
-
- vallie->Release();
- }
- 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);
- return PY_SET_ATTR_SUCCESS;
-};
-
PyObject* CValue::ConvertKeysToPython( void )
{
PyObject *pylist = PyList_New( 0 );