[Bf-python] tp_getset update
Ken Hughes
khughes at pacific.edu
Tue Aug 9 18:45:12 CEST 2005
Back from about 6 days on train riding across the US. I read through
all the BPy source files and noted what getStuff()/setStuff() methods
did not have corresponding attributes or used different arguments from
existing attributes. As of last last week I started implementing some
of the changes (which I'll upload to the patch tracker shortly) and (of
course) would appreciate feedback upon ASAP before continuing with other
modules (two of the most pressing implementation issues are mentioned
below). I also made some notes on inconsistencies in the API
implementation which, once I organize, I'll put on the wiki.
Some issues with the conversion so far:
(1) approximately 85% of the setters are "boilerplate", simply
taking either an integer or float, range-checking or clamping the value,
then assigning to an element in a structure. So I've implemented some
helper EXPP_* procedures (in gen_utils.c) which do much of the work.
For example:
static int Material_setHardness( BPy_Material * self, PyObject * value )
{
return EXPP_setShortClamped ( value, &self->material->har,
EXPP_MAT_HARD_MIN,
EXPP_MAT_HARD_MAX );
}
static int Lamp_setType( BPy_Lamp * self, PyObject * value )
{
return EXPP_setShortRange ( value, &self->lamp->type,
0, EXPP_LAMP_TYPE_MAX );
}
(2) approximately 90% of the setStuff() methods are also
"boilerplate"; for these, I'm implementing a *_setterWrapper() procedure:
static PyObject *X_setterWrapper ( BPy_X * self, PyObject * args,
int (*func)( BPy_X * self, PyObject * args ));
which check the arg type, retrieves it using PySequence_Get_Item() and
passes to the setter function (*func), then returns either Py_None or
NULL (for an exception). This makes the new setStuff() procedures very
simple (for example):
static PyObject *Camera_oldsetScale(BPy_Camera * self, PyObject * args)
{
return Camera_setterWrapper ( self, args, Camera_setScale );
}
(3) does anyone have an idea how the doc field in the tp_getset is
accessed? For example:
{"bias",
(getter)Lamp_getBias, (setter)Lamp_setBias,
"Lamp shadow map sampling bias",
NULL},
If I try "print lamp.bias.__doc__" I get a doc string explaining how to
use a float (which is the type of "bias"). I haven't found anything in
the Python docs which explain how to access this field; maybe it isn't
implemented yet?
Ken
More information about the Bf-python
mailing list