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:
authorElia Sarti <vekoon@gmail.com>2010-01-24 13:51:59 +0300
committerElia Sarti <vekoon@gmail.com>2010-01-24 13:51:59 +0300
commit9733e902a51e5b6ea42ea9ff28569b36ce9a307e (patch)
tree114e4c2038fe24b6747a6d387f1e99ec5cbb5143 /source/blender/makesrna/intern/rna_define.c
parent7c21eb7cd560fc62807ad8182a7b10635bc7d845 (diff)
RNA functions
Fixed and completed support for returning multiple values. This includes support for returning arrays, both fixed and dynamically sized. The way this is achieved is by storing an additional int value next to the dynamic parameter in the ParameterList stack which gets passed to the C function as an additional parameter. In the case of return parameters it is duty of the C function to set this int to the correct length value for the dynamic parameter (which makes sense). Note that for the dynamic output/return parameter it is assumed the function has allocated that memory (which gets freed automatically). Also, I cleaned the makesrna's bridge function generation code a bit and renamed PROP_RETURN to PROP_OUTPUT, which represents better the reality now that there are multiple returns. The function now to mark multiple returns (outputs) is RNA_def_function_output. For an example, look at Action.get_frame_range in rna_action_api.c, by the way Aligorith I removed the #ifdef for this function now that there's support for returning arrays, feel free to modify (the function seems to work).
Diffstat (limited to 'source/blender/makesrna/intern/rna_define.c')
-rw-r--r--source/blender/makesrna/intern/rna_define.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index ed10c0819fd..d2036c61f61 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -2419,17 +2419,26 @@ FunctionRNA *RNA_def_function_runtime(StructRNA *srna, const char *identifier, C
return func;
}
-/* C return value only!, multiple rna returns can be done with RNA_def_function_return_mark */
+/* C return value only!, multiple RNA returns can be done with RNA_def_function_output */
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
{
+ if (ret->flag & PROP_DYNAMIC) {
+ fprintf(stderr, "RNA_def_function_return: %s.%s, dynamic values are not allowed as strict returns, use RNA_def_function_output instead.\n", func->identifier, ret->identifier);
+ return;
+ }
+ else if (ret->arraydimension) {
+ fprintf(stderr, "RNA_def_function_return: %s.%s, arrays are not allowed as strict returns, use RNA_def_function_output instead.\n", func->identifier, ret->identifier);
+ return;
+ }
+
func->c_ret= ret;
- RNA_def_function_return_mark(func, ret);
+ RNA_def_function_output(func, ret);
}
-void RNA_def_function_return_mark(FunctionRNA *func, PropertyRNA *ret)
+void RNA_def_function_output(FunctionRNA *func, PropertyRNA *ret)
{
- ret->flag|=PROP_RETURN;
+ ret->flag|= PROP_OUTPUT;
}
void RNA_def_function_flag(FunctionRNA *func, int flag)
@@ -2448,6 +2457,7 @@ int rna_parameter_size(PropertyRNA *parm)
int len= parm->totarraylength; /* only supports fixed length at the moment */
if(len > 0) {
+ /* XXX in other parts is mentioned that strings can be dynamic as well */
if (parm->flag & PROP_DYNAMIC)
return sizeof(void *);
@@ -2497,6 +2507,18 @@ int rna_parameter_size(PropertyRNA *parm)
return sizeof(void *);
}
+/* this function returns the size of the memory allocated for the parameter,
+ useful for instance for memory alignment or for storing additional information */
+int rna_parameter_size_alloc(PropertyRNA *parm)
+{
+ int size = rna_parameter_size(parm);
+
+ if (parm->flag & PROP_DYNAMIC)
+ size+= sizeof(int);
+
+ return size;
+}
+
/* Dynamic Enums */
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item)