__str__ functions for other mathutils types

This commit is contained in:
2011-12-20 03:37:55 +00:00
parent 32b23b9f74
commit 3d8ee28750
7 changed files with 98 additions and 19 deletions

View File

@@ -35,6 +35,7 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_dynstr.h"
#define MAX_DIMENSIONS 4
@@ -1171,6 +1172,29 @@ static PyObject *Vector_repr(VectorObject *self)
return ret;
}
static PyObject *Vector_str(VectorObject *self)
{
int i;
DynStr *ds;
if (BaseMath_ReadCallback(self) == -1)
return NULL;
ds= BLI_dynstr_new();
BLI_dynstr_append(ds, "<Vector (");
for (i = 0; i < self->size; i++) {
BLI_dynstr_appendf(ds, i ? ", %.4f" : "%.4f", self->vec[i]);
}
BLI_dynstr_append(ds, ") >");
return mathutils_dynstr_to_py(ds); /* frees ds */
}
/* Sequence Protocol */
/* sequence length len(vector) */
static int Vector_len(VectorObject *self)
@@ -2715,7 +2739,7 @@ PyTypeObject vector_Type = {
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
(reprfunc)Vector_str, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */