diff options
author | Joseph Gilbert <ascotan@gmail.com> | 2005-08-17 18:26:00 +0400 |
---|---|---|
committer | Joseph Gilbert <ascotan@gmail.com> | 2005-08-17 18:26:00 +0400 |
commit | 8b060dd5adfe5d56f558e4a600717f2b755d8559 (patch) | |
tree | add7c4df0056bf27f4397ea62162668956630d49 /source/blender/python/api2_2x/gen_utils.c | |
parent | 2872263377aa48233bc4e6a8f298a3706464288c (diff) |
- update to constant.c
- give it the key/items interface
- creates some factory functions for const generation
- genutils methods
- method for getting module constants
- method for throwing errors with a print string
- updates to function names
- clean up interpreter launch a bit
Diffstat (limited to 'source/blender/python/api2_2x/gen_utils.c')
-rw-r--r-- | source/blender/python/api2_2x/gen_utils.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c index 6a0aff3a04e..1b60f5c3bae 100644 --- a/source/blender/python/api2_2x/gen_utils.c +++ b/source/blender/python/api2_2x/gen_utils.c @@ -39,6 +39,30 @@ #include "BKE_global.h" #include "BKE_main.h" +//---------------------- EXPP_GetModuleConstant ------------------------- +//Helper function for returning a module constant +PyObject *EXPP_GetModuleConstant(char *module, char *constant) +{ + PyObject *py_module = NULL, *py_dict = NULL, *py_constant = NULL; + + /*Careful to pass the correct Package.Module string here or + * else you add a empty module somewhere*/ + py_module = PyImport_AddModule(module); + if(!py_module){ //null = error returning module + return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, + "error encountered with returning module constant..." ) ); + } + py_dict = PyModule_GetDict(py_module); //never fails + + py_constant = PyDict_GetItemString(py_dict, constant); + if(!py_constant){ //null = key not found + return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, + "error encountered with returning module constant..." ) ); + } + + return EXPP_incr_ret(py_constant); +} + /*****************************************************************************/ /* Description: This function clamps an int to the given interval */ /* [min, max]. */ @@ -117,6 +141,33 @@ int EXPP_ReturnIntError( PyObject * type, char *error_msg ) return -1; } + +int EXPP_intError(PyObject *type, const char *format, ...) +{ + char *error = ""; + va_list vlist; + + va_start(vlist, format); + vsprintf(error, format, vlist); + va_end(vlist); + + PyErr_SetString(type, error); + return -1; +} +//Like EXPP_ReturnPyObjError but takes a printf format string and multiple arguments +PyObject *EXPP_objError(PyObject *type, const char *format, ...) +{ + char *error = ""; + va_list vlist; + + va_start(vlist, format); + vsprintf(error, format, vlist); + va_end(vlist); + + PyErr_SetString(type, error); + return NULL; +} + /*****************************************************************************/ /* Description: This function increments the reference count of the given */ /* Python object (usually Py_None) and returns it. */ |