- 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
This commit is contained in:
2005-08-17 14:26:00 +00:00
parent 2872263377
commit 8b060dd5ad
16 changed files with 435 additions and 361 deletions

View File

@@ -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. */