diff options
author | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-06-07 15:03:12 +0400 |
---|---|---|
committer | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-06-07 15:03:12 +0400 |
commit | c16444e624040bd51a86b5dfd743396eaed970d1 (patch) | |
tree | 8224a39a10bd2b16968394d2e185c1413c57ed13 /source/gameengine/Expressions | |
parent | b468bf726c50d3126fac2664164e1be0d6e209c5 (diff) |
Python updates:
Added scene module
Diffstat (limited to 'source/gameengine/Expressions')
-rw-r--r-- | source/gameengine/Expressions/ListValue.cpp | 15 | ||||
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.h | 32 | ||||
-rw-r--r-- | source/gameengine/Expressions/Value.h | 31 |
3 files changed, 44 insertions, 34 deletions
diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 3ee8a5a3501..cd16377b5e3 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -53,8 +53,17 @@ PyObject* listvalue_mapping_subscript(PyObject* list,PyObject* pyindex) return (PyObject*) item; } - Py_Error(PyExc_IndexError, "Python ListIndex out of range"); - Py_Return; + if (PyInt_Check(pyindex)) + { + int index = PyInt_AsLong(pyindex); + return listvalue_buffer_item(list, index); + } + + PyObject *pyindex_str = PyObject_Repr(pyindex); /* new ref */ + STR_String index_str(PyString_AsString(pyindex_str)); + PyErr_Format(PyExc_KeyError, "'%s' not in list", index_str.Ptr()); + Py_DECREF(pyindex_str); + return NULL; } @@ -189,7 +198,7 @@ PyTypeObject CListValue::Type = { __repr, /*tp_repr*/ 0, /*tp_as_number*/ &listvalue_as_sequence, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ + &instance_as_mapping, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call */ }; diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 7c5f531f35b..8a5e8ef2d7b 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -82,6 +82,38 @@ inline void Py_Fatal(char *M) { else \ return rvalue +/** + * These macros are helpfull when embedding Python routines. The second + * macro is one that also requires a documentation string + */ +#define KX_PYMETHOD(class_name, method_name) \ + PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \ + static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ + return ((class_name*) self)->Py##method_name(self, args, kwds); \ + }; \ + +#define KX_PYMETHOD_DOC(class_name, method_name) \ + PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \ + static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ + return ((class_name*) self)->Py##method_name(self, args, kwds); \ + }; \ + static char method_name##_doc[]; \ + +/* The line above should remain empty */ +/** + * Method table macro (with doc) + */ +#define KX_PYMETHODTABLE(class_name, method_name) \ + {#method_name , (PyCFunction) class_name::sPy##method_name, METH_VARARGS, class_name::method_name##_doc} + +/** + * Function implementation macro + */ +#define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \ +char class_name::method_name##_doc[] = doc_string; \ +PyObject* class_name::Py##method_name(PyObject* self, PyObject* args, PyObject* kwds) + + /*------------------------------ * PyObjectPlus diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index 4656e2ca5ac..d30e8a26d97 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -182,37 +182,6 @@ public: // // -/** - * These macros are helpfull when embedding Python routines. The second - * macro is one that also requires a documentation string - */ -#define KX_PYMETHOD(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \ - static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ - return ((class_name*) self)->Py##method_name(self, args, kwds); \ - }; \ - -#define KX_PYMETHOD_DOC(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \ - static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ - return ((class_name*) self)->Py##method_name(self, args, kwds); \ - }; \ - static char method_name##_doc[]; \ - -/* The line above should remain empty */ -/** - * Method table macro (with doc) - */ -#define KX_PYMETHODTABLE(class_name, method_name) \ - {#method_name , (PyCFunction) class_name::sPy##method_name, METH_VARARGS, class_name::method_name##_doc} - -/** - * Function implementation macro - */ -#define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \ -char class_name::method_name##_doc[] = doc_string; \ -PyObject* class_name::Py##method_name(PyObject* self, PyObject* args, PyObject* kwds) - #ifndef NO_EXP_PYTHON_EMBEDDING |