diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-08-14 07:23:36 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-08-14 07:23:36 +0400 |
commit | 3f2cb6e87855e4afc2e26d87f36817a92490429e (patch) | |
tree | 8c9af32f0aa1e42a08cc6d9d2aac3f1c6c052535 /source/gameengine/Expressions | |
parent | d2750f7bda1e5e4e43df330ab49e677105e00d4f (diff) |
game engine python api
* removed macros that were not used much, some misleading.
* removed error string setting calls that overwrote the error set by PyArg_ParseTuple with a less useful one.
* use python macros Py_RETURN_NONE, Py_RETURN_TRUE, Py_RETURN_FALSE
Diffstat (limited to 'source/gameengine/Expressions')
-rw-r--r-- | source/gameengine/Expressions/InputParser.cpp | 5 | ||||
-rw-r--r-- | source/gameengine/Expressions/ListValue.cpp | 13 | ||||
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.cpp | 12 | ||||
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.h | 15 | ||||
-rw-r--r-- | source/gameengine/Expressions/Value.cpp | 16 | ||||
-rw-r--r-- | source/gameengine/Expressions/Value.h | 2 |
6 files changed, 25 insertions, 38 deletions
diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index 24033dd21a2..32a9de32e21 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -631,7 +631,8 @@ void CParser::SetContext(CValue* context) PyObject* CParserPyMake(PyObject* ignored,PyObject* args) { char* txt; - Py_Try(PyArg_ParseTuple(args,"s",&txt)); + if (!PyArg_ParseTuple(args,"s",&txt)) + return NULL; CParser parser; CExpression* expr = parser.ProcessText(txt); CValue* val = expr->Calculate(); @@ -641,7 +642,7 @@ PyObject* CParserPyMake(PyObject* ignored,PyObject* args) static PyMethodDef CParserMethods[] = { - { "calc", CParserPyMake , Py_NEWARGS}, + { "calc", CParserPyMake , METH_VARARGS}, { NULL,NULL} // Sentinel }; diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index bbf58a8a06e..9ffdbb1223c 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -43,7 +43,7 @@ PyObject* listvalue_buffer_item(PyObject* list,Py_ssize_t index) return ((CListValue*) list)->GetValue(index)->AddRef(); } - Py_Error(PyExc_IndexError, "Python ListIndex out of range"); + PyErr_SetString(PyExc_IndexError, "Python ListIndex out of range"); return NULL; } @@ -130,9 +130,10 @@ listvalue_buffer_concat(PyObject * self, PyObject * other) } } - if (error) - Py_Error(PyExc_SystemError, "Python Error: couldn't add one or more items to a list"); - + if (error) { + PyErr_SetString(PyExc_SystemError, "Python Error: couldn't add one or more items to a list"); + return NULL; + } } else { @@ -155,8 +156,8 @@ listvalue_buffer_concat(PyObject * self, PyObject * other) listval->Add(objval); } else { - Py_Error(PyExc_SystemError, "Python Error: couldn't add item to a list"); - // bad luck + PyErr_SetString(PyExc_SystemError, "Python Error: couldn't add item to a list"); + return NULL; } } } diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index aabcd6cb71d..8937f481922 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, Py_NEWARGS}, + {"isA", (PyCFunction) sPy_isA, METH_VARARGS}, {NULL, NULL} /* Sentinel */ }; @@ -134,7 +134,8 @@ int PyObjectPlus::_setattr(const STR_String& attr, PyObject *value) ------------------------------*/ PyObject *PyObjectPlus::_repr(void) { - Py_Error(PyExc_SystemError, "Representation not overridden by object."); + PyErr_SetString(PyExc_SystemError, "Representation not overridden by object."); + return NULL; } /*------------------------------ @@ -164,11 +165,12 @@ bool PyObjectPlus::isA(const char *mytypename) // check typename of each parent PyObject *PyObjectPlus::Py_isA(PyObject *args) // Python wrapper for isA { char *mytypename; - Py_Try(PyArg_ParseTuple(args, "s", &mytypename)); + if (!PyArg_ParseTuple(args, "s", &mytypename)) + return NULL; if(isA(mytypename)) - {Py_INCREF(Py_True); return Py_True;} + Py_RETURN_TRUE; else - {Py_INCREF(Py_False); return Py_False;}; + Py_RETURN_FALSE; } #endif //NO_EXP_PYTHON_EMBEDDING diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 2bcb604dd23..595940274c4 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -44,22 +44,7 @@ ------------------------------*/ // some basic python macros -#define Py_NEWARGS 1 #define Py_Return { Py_INCREF(Py_None); return Py_None;} -static inline PyObject* Py_Success(bool truth) -{ - if (truth) - { - Py_INCREF(Py_True); - return Py_True; - } - Py_INCREF(Py_False); - return Py_False; -} - -#define Py_Error(E, M) {PyErr_SetString(E, M); return NULL;} -#define Py_Try(F) {if (!(F)) return NULL;} -#define Py_Assert(A,E,M) {if (!(A)) {PyErr_SetString(E, M); return NULL;}} static inline void Py_Fatal(char *M) { //cout << M << endl; diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index b4694740679..7bcb45228db 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -158,15 +158,14 @@ PyParentObject CValue::Parents[] = { }; PyMethodDef CValue::Methods[] = { -// { "printHello", (PyCFunction) CValue::sPyPrintHello, Py_NEWARGS}, - { "getName", (PyCFunction) CValue::sPyGetName, Py_NEWARGS}, +// { "printHello", (PyCFunction) CValue::sPyPrintHello, METH_VARARGS}, + { "getName", (PyCFunction) CValue::sPyGetName, METH_NOARGS}, {NULL,NULL} //Sentinel }; -PyObject* CValue::PyGetName(PyObject* self,PyObject* args,PyObject* kwds) +PyObject* CValue::PyGetName(PyObject* self) { - PyObject* pyname = PyString_FromString(this->GetName()); - return pyname; + return PyString_FromString(this->GetName()); } /*#define CVALUE_DEBUG*/ @@ -662,7 +661,7 @@ CValue* CValue::FindIdentifier(const STR_String& identifiername) static PyMethodDef CValueMethods[] = { - //{ "new", CValue::PyMake , Py_NEWARGS}, + //{ "new", CValue::PyMake , METH_VARARGS}, { NULL,NULL} // Sentinel }; @@ -806,9 +805,8 @@ PyObject* CValue::ConvertKeysToPython( void ) PyObject* CValue::PyMake(PyObject* ignored,PyObject* args) { - //Py_Try(PyArg_ParseTuple(args,"s",&name)); - Py_INCREF(Py_None); - return Py_None;//new CValue(); + //if (!PyArg_ParseTuple(args,"s",&name)) return NULL; + Py_RETURN_NONE;//new CValue(); } */ diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index bcf231cf4f0..74fcdae5756 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -255,7 +255,7 @@ public: virtual PyObject* ConvertKeysToPython( void ); - KX_PYMETHOD(CValue,GetName); + KX_PYMETHOD_NOARGS(CValue,GetName); #else CValue(); |