Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-02-01 13:51:34 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-02-01 13:51:34 +0300
commit53f8bbd798615c4108d8012dc5adb1c852f27bd3 (patch)
tree29d5a53136bf761457dfacdd9b77f4459e1e1bdc /source/blender/python/intern/bpy_util.c
parent30dcd5a4b5ded9b7e2523b891c89342eada33ffd (diff)
bpy.props.IntVectorProperty & BoolVectorProperty
Diffstat (limited to 'source/blender/python/intern/bpy_util.c')
-rw-r--r--source/blender/python/intern/bpy_util.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c
index 2cd1337fba7..8b5987d6c94 100644
--- a/source/blender/python/intern/bpy_util.c
+++ b/source/blender/python/intern/bpy_util.c
@@ -373,3 +373,56 @@ int BPy_errors_to_report(ReportList *reports)
return 1;
}
+/* array utility function */
+int BPyAsPrimitiveArray(void *array, PyObject *value, int length, PyTypeObject *type, char *error_prefix)
+{
+ PyObject *value_fast;
+ int value_len;
+ int i;
+
+ if(!(value_fast=PySequence_Fast(value, error_prefix))) {
+ return -1;
+ }
+
+ value_len= PySequence_Fast_GET_SIZE(value_fast);
+
+ if(value_len != length) {
+ Py_DECREF(value);
+ PyErr_Format(PyExc_TypeError, "%s: invalid sequence length. expected %d, got %d.", error_prefix, length, value_len);
+ return -1;
+ }
+
+ /* for each type */
+ if(type == &PyFloat_Type) {
+ float *array_float= array;
+ for(i=0; i<length; i++) {
+ array_float[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
+ }
+ }
+ else if(type == &PyLong_Type) {
+ int *array_int= array;
+ for(i=0; i<length; i++) {
+ array_int[i] = PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i));
+ }
+ }
+ else if(type == &PyBool_Type) {
+ int *array_bool= array;
+ for(i=0; i<length; i++) {
+ array_bool[i] = (PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i)) != 0);
+ }
+ }
+ else {
+ Py_DECREF(value_fast);
+ PyErr_Format(PyExc_TypeError, "%s: internal error %s is invalid.", error_prefix, type->tp_name);
+ return -1;
+ }
+
+ Py_DECREF(value_fast);
+
+ if(PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError, "%s: one or more items could not be used as a %s.", error_prefix, type->tp_name);
+ return -1;
+ }
+
+ return 0;
+}