RNA: C API

* RNA_blender.h is now generated along with the other files. It is not
  used anywhere yet, and still located quite hidden next to the other
  rna_*_gen.c files. Read only access for now.
* Inherited properties are not copied from the base anymore but
  iterated over. Patch by Vekoon, thanks!
* Array get/set callbacks now do the whole array instead of getting an
  index. This is needed for some layers for example so python can set
  the array as a whole, otherwise the check that one layer has to be
  enabled at all times gets in the way. Also nicer for the C API.
* Also some changes to returning pointers to make the API cleaner, got
  rid of the type() callback and instead let get() return PointerRNA
  with the type included.

The C API looks like this currently:
http://users.pandora.be/blendix/RNA_blender.h
This commit is contained in:
2009-02-02 19:57:57 +00:00
parent eb00687cde
commit 284db61572
39 changed files with 1277 additions and 761 deletions

View File

@@ -163,7 +163,7 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
case PROP_POINTER:
{
PointerRNA newptr;
RNA_property_pointer_get(ptr, prop, &newptr);
newptr= RNA_property_pointer_get(ptr, prop);
if (newptr.data) {
ret = pyrna_struct_CreatePyObject(&newptr);
} else {
@@ -209,7 +209,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
switch (type) {
case PROP_BOOLEAN:
{
signed char *param_arr = MEM_mallocN(sizeof(char) * len, "pyrna bool array");
int *param_arr = MEM_mallocN(sizeof(char) * len, "pyrna bool array");
/* collect the variables before assigning, incase one of them is incorrect */
for (i=0; i<len; i++) {
@@ -224,9 +224,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
}
}
for (i=0; i<len; i++) {
RNA_property_boolean_set_array(ptr, prop, i, param_arr[i]);
}
RNA_property_boolean_set_array(ptr, prop, param_arr);
MEM_freeN(param_arr);
break;
@@ -248,9 +246,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
return -1;
}
for (i=0; i<len; i++) {
RNA_property_int_set_array(ptr, prop, i, param_arr[i]);
}
RNA_property_int_set_array(ptr, prop, param_arr);
MEM_freeN(param_arr);
break;
@@ -272,9 +268,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
return -1;
}
for (i=0; i<len; i++) {
RNA_property_float_set_array(ptr, prop, i, param_arr[i]);
}
RNA_property_float_set_array(ptr, prop, param_arr);
MEM_freeN(param_arr);
break;
@@ -385,13 +379,13 @@ static PyObject * pyrna_prop_to_py_index(PointerRNA *ptr, PropertyRNA *prop, int
/* see if we can coorce into a python type - PropertyType */
switch (type) {
case PROP_BOOLEAN:
ret = PyBool_FromLong( RNA_property_boolean_get_array(ptr, prop, index) );
ret = PyBool_FromLong( RNA_property_boolean_get_index(ptr, prop, index) );
break;
case PROP_INT:
ret = PyLong_FromSize_t( (size_t)RNA_property_int_get_array(ptr, prop, index) );
ret = PyLong_FromSize_t( (size_t)RNA_property_int_get_index(ptr, prop, index) );
break;
case PROP_FLOAT:
ret = PyFloat_FromDouble( RNA_property_float_get_array(ptr, prop, index) );
ret = PyFloat_FromDouble( RNA_property_float_get_index(ptr, prop, index) );
break;
default:
PyErr_SetString(PyExc_AttributeError, "not an array type");
@@ -419,7 +413,7 @@ static int pyrna_py_to_prop_index(PointerRNA *ptr, PropertyRNA *prop, int index,
PyErr_SetString(PyExc_TypeError, "expected True/False or 0/1");
ret = -1;
} else {
RNA_property_boolean_set_array(ptr, prop, index, param);
RNA_property_boolean_set_index(ptr, prop, index, param);
}
break;
}
@@ -430,7 +424,7 @@ static int pyrna_py_to_prop_index(PointerRNA *ptr, PropertyRNA *prop, int index,
PyErr_SetString(PyExc_TypeError, "expected an int type");
ret = -1;
} else {
RNA_property_int_set_array(ptr, prop, index, param);
RNA_property_int_set_index(ptr, prop, index, param);
}
break;
}
@@ -441,7 +435,7 @@ static int pyrna_py_to_prop_index(PointerRNA *ptr, PropertyRNA *prop, int index,
PyErr_SetString(PyExc_TypeError, "expected a float type");
ret = -1;
} else {
RNA_property_float_set_array(ptr, prop, index, param);
RNA_property_float_set_index(ptr, prop, index, param);
}
break;
}
@@ -679,7 +673,7 @@ PyObject *pyrna_struct_to_docstring(BPy_StructRNA *self)
// TODO - why does this crash sometimes
// PointerRNA newptr;
// RNA_property_pointer_get(&iter.ptr, prop, &newptr);
// newptr= RNA_property_pointer_get(&iter.ptr, prop);
// Use this instead, its not that useful
BLI_dynstr_appendf(dynstr, "@type %s: PyRNA %s\n", identifier, RNA_struct_identifier(&iter.ptr));