diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-20 07:37:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-20 07:37:55 +0400 |
commit | 3d8ee287509f3a0dac535914a7193397217b006c (patch) | |
tree | 2a2fc72b6151fd21bef9c29248ee2b59da443044 /source/blender/python/mathutils/mathutils_Vector.c | |
parent | 32b23b9f746b9bec4023da1d2ef6085fbbde9ae7 (diff) |
__str__ functions for other mathutils types
Diffstat (limited to 'source/blender/python/mathutils/mathutils_Vector.c')
-rw-r--r-- | source/blender/python/mathutils/mathutils_Vector.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index aedf60e7191..6249a340c3f 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -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; */ |