use bool for rna funcs.
[blender.git] / source / blender / makesrna / intern / makesrna.c
index 6b6da122b3c82c1eb836debe81216bfff742a8c0..f3891c20ab55b00e1202a8eff5318c8f33dbf063 100644 (file)
@@ -24,7 +24,6 @@
  *  \ingroup RNA
  */
 
  *  \ingroup RNA
  */
 
-
 #include <float.h>
 #include <limits.h>
 #include <stdio.h>
 #include <float.h>
 #include <limits.h>
 #include <stdio.h>
@@ -34,6 +33,8 @@
 
 #include "MEM_guardedalloc.h"
 
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
+
 #include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_types.h"
 #include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_types.h"
@@ -80,16 +81,18 @@ static void rna_generate_static_parameter_prototypes(FILE *f, StructRNA *srna, F
                                                      const char *name_override, int close_prototype);
 
 /* helpers */
                                                      const char *name_override, int close_prototype);
 
 /* helpers */
-#define WRITE_COMMA { \
+#define WRITE_COMMA \
+       { \
                if (!first) \
                        fprintf(f, ", "); \
                first = 0; \
        } (void)0
 
                if (!first) \
                        fprintf(f, ", "); \
                first = 0; \
        } (void)0
 
-#define WRITE_PARAM(param) { \
+#define WRITE_PARAM(param) \
+       { \
                WRITE_COMMA; \
                fprintf(f, param); \
                WRITE_COMMA; \
                fprintf(f, param); \
-       }
+       } (void)0
 
 static int replace_if_different(char *tmpfile, const char *dep_files[])
 {
 
 static int replace_if_different(char *tmpfile, const char *dep_files[])
 {
@@ -413,10 +416,10 @@ static const char *rna_type_type_name(PropertyRNA *prop)
                        return "float";
                case PROP_STRING:
                        if (prop->flag & PROP_THICK_WRAP) {
                        return "float";
                case PROP_STRING:
                        if (prop->flag & PROP_THICK_WRAP) {
-                               return "char*";
+                               return "char *";
                        }
                        else {
                        }
                        else {
-                               return "const char*";
+                               return "const char *";
                        }
                default:
                        return NULL;
                        }
                default:
                        return NULL;
@@ -657,17 +660,17 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                                                                        "get_length");
                                                fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
                                                fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
                                                                                        "get_length");
                                                fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
                                                fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
-                                               fprintf(f, "    for (i=0; i<len; i++) {\n");
+                                               fprintf(f, "    for (i=0; i < len; i++) {\n");
                                                MEM_freeN(lenfunc);
                                        }
                                        else {
                                                fprintf(f, "    int i;\n\n");
                                                MEM_freeN(lenfunc);
                                        }
                                        else {
                                                fprintf(f, "    int i;\n\n");
-                                               fprintf(f, "    for (i=0; i<%u; i++) {\n", prop->totarraylength);
+                                               fprintf(f, "    for (i=0; i < %u; i++) {\n", prop->totarraylength);
                                        }
 
                                        if (dp->dnaarraylength == 1) {
                                                if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
                                        }
 
                                        if (dp->dnaarraylength == 1) {
                                                if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
-                                                       fprintf(f, "            values[i] = %s((data->%s & (%d<<i)) != 0);\n",
+                                                       fprintf(f, "            values[i] = %s((data->%s & (%d << i)) != 0);\n",
                                                                (dp->booleannegative) ? "!" : "", dp->dnaname, dp->booleanbit);
                                                }
                                                else {
                                                                (dp->booleannegative) ? "!" : "", dp->dnaname, dp->booleanbit);
                                                }
                                                else {
@@ -683,7 +686,7 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                                        fprintf(f, ") != 0);\n");
                                                }
                                                else if (rna_color_quantize(prop, dp)) {
                                                        fprintf(f, ") != 0);\n");
                                                }
                                                else if (rna_color_quantize(prop, dp)) {
-                                                       fprintf(f, "            values[i] = (%s)(data->%s[i]*(1.0f/255.0f));\n",
+                                                       fprintf(f, "            values[i] = (%s)(data->%s[i]*(1.0f / 255.0f));\n",
                                                                rna_type_type(prop), dp->dnaname);
                                                }
                                                else if (dp->dnatype) {
                                                                rna_type_type(prop), dp->dnaname);
                                                }
                                                else if (dp->dnatype) {
@@ -758,7 +761,7 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
        if (prop->type == PROP_INT) {
                IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
 
        if (prop->type == PROP_INT) {
                IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
 
-               if (iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
+               if (iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX || iprop->range) {
                        if (array) fprintf(f, "CLAMPIS(values[i], ");
                        else fprintf(f, "CLAMPIS(value, ");
                        if (iprop->range) {
                        if (array) fprintf(f, "CLAMPIS(values[i], ");
                        else fprintf(f, "CLAMPIS(value, ");
                        if (iprop->range) {
@@ -774,7 +777,7 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
        else if (prop->type == PROP_FLOAT) {
                FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
 
        else if (prop->type == PROP_FLOAT) {
                FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
 
-               if (fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
+               if (fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX || fprop->range) {
                        if (array) fprintf(f, "CLAMPIS(values[i], ");
                        else fprintf(f, "CLAMPIS(value, ");
                        if (fprop->range) {
                        if (array) fprintf(f, "CLAMPIS(values[i], ");
                        else fprintf(f, "CLAMPIS(value, ");
                        if (fprop->range) {
@@ -868,16 +871,16 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
 
                                if (prop->flag & PROP_ID_REFCOUNT) {
                                        fprintf(f, "\n  if (data->%s)\n", dp->dnaname);
 
                                if (prop->flag & PROP_ID_REFCOUNT) {
                                        fprintf(f, "\n  if (data->%s)\n", dp->dnaname);
-                                       fprintf(f, "            id_us_min((ID*)data->%s);\n", dp->dnaname);
+                                       fprintf(f, "            id_us_min((ID *)data->%s);\n", dp->dnaname);
                                        fprintf(f, "    if (value.data)\n");
                                        fprintf(f, "    if (value.data)\n");
-                                       fprintf(f, "            id_us_plus((ID*)value.data);\n\n");
+                                       fprintf(f, "            id_us_plus((ID *)value.data);\n\n");
                                }
                                else {
                                        PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
                                        StructRNA *type = rna_find_struct((const char *)pprop->type);
                                        if (type && (type->flag & STRUCT_ID)) {
                                                fprintf(f, "    if (value.data)\n");
                                }
                                else {
                                        PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
                                        StructRNA *type = rna_find_struct((const char *)pprop->type);
                                        if (type && (type->flag & STRUCT_ID)) {
                                                fprintf(f, "    if (value.data)\n");
-                                               fprintf(f, "            id_lib_extern((ID*)value.data);\n\n");
+                                               fprintf(f, "            id_lib_extern((ID *)value.data);\n\n");
                                        }
                                }
 
                                        }
                                }
 
@@ -908,20 +911,20 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                                fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
                                                fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
                                                rna_clamp_value_range(f, prop);
                                                fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
                                                fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
                                                rna_clamp_value_range(f, prop);
-                                               fprintf(f, "    for (i=0; i<len; i++) {\n");
+                                               fprintf(f, "    for (i=0; i < len; i++) {\n");
                                                MEM_freeN(lenfunc);
                                        }
                                        else {
                                                fprintf(f, "    int i;\n\n");
                                                rna_clamp_value_range(f, prop);
                                                MEM_freeN(lenfunc);
                                        }
                                        else {
                                                fprintf(f, "    int i;\n\n");
                                                rna_clamp_value_range(f, prop);
-                                               fprintf(f, "    for (i=0; i<%u; i++) {\n", prop->totarraylength);
+                                               fprintf(f, "    for (i=0; i < %u; i++) {\n", prop->totarraylength);
                                        }
 
                                        if (dp->dnaarraylength == 1) {
                                                if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
                                                        fprintf(f, "            if (%svalues[i]) data->%s |= (%d<<i);\n",
                                                                (dp->booleannegative) ? "!" : "", dp->dnaname, dp->booleanbit);
                                        }
 
                                        if (dp->dnaarraylength == 1) {
                                                if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
                                                        fprintf(f, "            if (%svalues[i]) data->%s |= (%d<<i);\n",
                                                                (dp->booleannegative) ? "!" : "", dp->dnaname, dp->booleanbit);
-                                                       fprintf(f, "            else data->%s &= ~(%d<<i);\n", dp->dnaname, dp->booleanbit);
+                                                       fprintf(f, "            else data->%s &= ~(%d << i);\n", dp->dnaname, dp->booleanbit);
                                                }
                                                else {
                                                        fprintf(f, "            (&data->%s)[i] = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
                                                }
                                                else {
                                                        fprintf(f, "            (&data->%s)[i] = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
@@ -1045,9 +1048,9 @@ static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA
                else {
                        rna_print_data_get(f, dp);
                        if (dp->dnalengthname)
                else {
                        rna_print_data_get(f, dp);
                        if (dp->dnalengthname)
-                               fprintf(f, "    return (data->%s == NULL)? 0: data->%s;\n", dp->dnaname, dp->dnalengthname);
+                               fprintf(f, "    return (data->%s == NULL) ? 0 : data->%s;\n", dp->dnaname, dp->dnalengthname);
                        else
                        else
-                               fprintf(f, "    return (data->%s == NULL)? 0: %d;\n", dp->dnaname, dp->dnalengthfixed);
+                               fprintf(f, "    return (data->%s == NULL) ? 0 : %d;\n", dp->dnaname, dp->dnalengthfixed);
                }
                fprintf(f, "}\n\n");
        }
                }
                fprintf(f, "}\n\n");
        }
@@ -1082,7 +1085,7 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *
 
        fprintf(f, "\n  memset(iter, 0, sizeof(*iter));\n");
        fprintf(f, "    iter->parent= *ptr;\n");
 
        fprintf(f, "\n  memset(iter, 0, sizeof(*iter));\n");
        fprintf(f, "    iter->parent= *ptr;\n");
-       fprintf(f, "    iter->prop= (PropertyRNA*)&rna_%s_%s;\n", srna->identifier, prop->identifier);
+       fprintf(f, "    iter->prop= (PropertyRNA *)&rna_%s_%s;\n", srna->identifier, prop->identifier);
 
        if (dp->dnalengthname || dp->dnalengthfixed) {
                if (manualfunc) {
 
        if (dp->dnalengthname || dp->dnalengthfixed) {
                if (manualfunc) {
@@ -1221,6 +1224,89 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property
        return func;
 }
 
        return func;
 }
 
+static char *rna_def_property_lookup_string_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
+                                                 const char *manualfunc, const char *item_type)
+{
+       char *func;
+       StructRNA *item_srna, *item_name_base;
+       PropertyRNA *item_name_prop;
+       const int namebuflen = 1024;
+
+       if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
+               return NULL;
+
+       if (!manualfunc) {
+               if (!dp->dnastructname || !dp->dnaname)
+                       return NULL;
+
+               /* only supported for collection items with name properties */
+               item_srna = rna_find_struct(item_type);
+               if (item_srna && item_srna->nameproperty) {
+                       item_name_prop = item_srna->nameproperty;
+                       item_name_base = item_srna;
+                       while (item_name_base->base && item_name_base->base->nameproperty == item_name_prop)
+                               item_name_base = item_name_base->base;
+               }
+               else
+                       return NULL;
+       }
+
+       func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_string");
+
+       fprintf(f, "int %s(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)\n", func);
+       fprintf(f, "{\n");
+
+       if (manualfunc) {
+               fprintf(f, "    return %s(ptr, key, r_ptr);\n", manualfunc);
+               fprintf(f, "}\n\n");
+               return func;
+       }
+
+       /* XXX extern declaration could be avoid by including RNA_blender.h, but this has lots of unknown
+        * DNA types in functions, leading to conflicting function signatures.
+        */
+       fprintf(f, "    extern int %s_%s_length(PointerRNA *);\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
+       fprintf(f, "    extern void %s_%s_get(PointerRNA *, char *);\n\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
+
+       fprintf(f, "    int found= 0;\n");
+       fprintf(f, "    CollectionPropertyIterator iter;\n");
+       fprintf(f, "    char namebuf[%d];\n", namebuflen);
+       fprintf(f, "    char *name;\n\n");
+
+       fprintf(f, "    %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
+
+       fprintf(f, "    while (iter.valid) {\n");
+       fprintf(f, "            int namelen = %s_%s_length(&iter.ptr);\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
+       fprintf(f, "            if (namelen < %d) {\n", namebuflen);
+       fprintf(f, "                    %s_%s_get(&iter.ptr, namebuf);\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
+       fprintf(f, "                    if (strcmp(namebuf, key) == 0) {\n");
+       fprintf(f, "                            found = 1;\n");
+       fprintf(f, "                            *r_ptr = iter.ptr;\n");
+       fprintf(f, "                            break;\n");
+       fprintf(f, "                    }\n");
+       fprintf(f, "            }\n");
+       fprintf(f, "            else {\n");
+       fprintf(f, "                    name = MEM_mallocN(namelen+1, \"name string\");\n");
+       fprintf(f, "                    %s_%s_get(&iter.ptr, name);\n", item_name_base->identifier, rna_safe_id(item_name_prop->identifier));
+       fprintf(f, "                    if (strcmp(name, key) == 0) {\n");
+       fprintf(f, "                            MEM_freeN(name);\n\n");
+       fprintf(f, "                            found = 1;\n");
+       fprintf(f, "                            *r_ptr = iter.ptr;\n");
+       fprintf(f, "                            break;\n");
+       fprintf(f, "                    }\n");
+       fprintf(f, "                    else\n");
+       fprintf(f, "                            MEM_freeN(name);\n");
+       fprintf(f, "            }\n");
+       fprintf(f, "            %s_%s_next(&iter);\n", srna->identifier, rna_safe_id(prop->identifier));
+       fprintf(f, "    }\n");
+       fprintf(f, "    %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier));
+
+       fprintf(f, "    return found;\n");
+       fprintf(f, "}\n\n");
+
+       return func;
+}
+
 static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *UNUSED(dp),
                                         const char *manualfunc)
 {
 static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *UNUSED(dp),
                                         const char *manualfunc)
 {
@@ -1401,6 +1487,7 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
                {
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
                        const char *nextfunc = (const char *)cprop->next;
                {
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
                        const char *nextfunc = (const char *)cprop->next;
+                       const char *item_type = (const char *)cprop->item_type;
 
                        if (dp->dnatype && strcmp(dp->dnatype, "ListBase") == 0) {
                                /* pass */
 
                        if (dp->dnatype && strcmp(dp->dnatype, "ListBase") == 0) {
                                /* pass */
@@ -1424,6 +1511,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
                        cprop->end = (void *)rna_def_property_end_func(f, srna, prop, dp, (const char *)cprop->end);
                        cprop->lookupint = (void *)rna_def_property_lookup_int_func(f, srna, prop, dp,
                                                                                    (const char *)cprop->lookupint, nextfunc);
                        cprop->end = (void *)rna_def_property_end_func(f, srna, prop, dp, (const char *)cprop->end);
                        cprop->lookupint = (void *)rna_def_property_lookup_int_func(f, srna, prop, dp,
                                                                                    (const char *)cprop->lookupint, nextfunc);
+                       cprop->lookupstring = (void *)rna_def_property_lookup_string_func(f, srna, prop, dp,
+                                                                                         (const char *)cprop->lookupstring, item_type);
 
                        if (!(prop->flag & PROP_IDPROPERTY)) {
                                if (!cprop->begin) {
 
                        if (!(prop->flag & PROP_IDPROPERTY)) {
                                if (!cprop->begin) {
@@ -1541,12 +1630,16 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR
                }
                case PROP_COLLECTION:
                {
                }
                case PROP_COLLECTION:
                {
+                       CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
                        fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
                        fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
                        fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
                        fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
                        fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
                        fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
-                       /*fprintf(f, "int %slength(PointerRNA *ptr);\n", func); */
-                       /*fprintf(f, "void %slookup_int(PointerRNA *ptr, int key, StructRNA **type);\n", func); */
-                       /*fprintf(f, "void %slookup_string(PointerRNA *ptr, const char *key, StructRNA **type);\n", func); */
+                       if (cprop->length)
+                               fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
+                       if (cprop->lookupint)
+                               fprintf(f, "int %slookup_int(PointerRNA *ptr, int key, PointerRNA *r_ptr);\n", func);
+                       if (cprop->lookupstring)
+                               fprintf(f, "int %slookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr);\n", func);
                        break;
                }
        }
                        break;
                }
        }
@@ -1657,6 +1750,7 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property
                case PROP_STRING:
                {
                        fprintf(f, "\tinline std::string %s(void);", rna_safe_id(prop->identifier));
                case PROP_STRING:
                {
                        fprintf(f, "\tinline std::string %s(void);", rna_safe_id(prop->identifier));
+                       fprintf(f, "\tinline void %s(const std::string& value);", rna_safe_id(prop->identifier));
                        break;
                }
                case PROP_POINTER:
                        break;
                }
                case PROP_POINTER:
@@ -1672,13 +1766,19 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property
                case PROP_COLLECTION:
                {
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
                case PROP_COLLECTION:
                {
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
+                       const char *collection_funcs = "DefaultCollectionFunctions";
+
+                       if (!(dp->prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN)) && cprop->property.srna)
+                               collection_funcs  = (char *)cprop->property.srna;
 
                        if (cprop->item_type)
 
                        if (cprop->item_type)
-                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (const char *)cprop->item_type, srna->identifier,
-                                       rna_safe_id(prop->identifier));
+                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s, %s)", collection_funcs, (const char *)cprop->item_type, srna->identifier,
+                                       rna_safe_id(prop->identifier), (cprop->length ? "TRUE" : "FALSE"),
+                                       (cprop->lookupint ? "TRUE" : "FALSE"), (cprop->lookupstring ? "TRUE" : "FALSE"));
                        else
                        else
-                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier,
-                                       rna_safe_id(prop->identifier));
+                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s, %s)", collection_funcs, "UnknownType", srna->identifier,
+                                       rna_safe_id(prop->identifier), (cprop->length ? "TRUE" : "FALSE"),
+                                       (cprop->lookupint ? "TRUE" : "FALSE"), (cprop->lookupstring ? "TRUE" : "FALSE"));
                        break;
                }
        }
                        break;
                }
        }
@@ -1699,7 +1799,7 @@ static const char *rna_parameter_type_cpp_name(PropertyRNA *prop)
        }
 }
 
        }
 }
 
-static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc,
+static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *UNUSED(srna), FunctionDefRNA *dfunc,
                                                   const char *namespace, int close_prototype)
 {
        PropertyDefRNA *dp;
                                                   const char *namespace, int close_prototype)
 {
        PropertyDefRNA *dp;
@@ -1724,9 +1824,6 @@ static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *srna, Func
        if (func->flag & FUNC_USE_CONTEXT)
                WRITE_PARAM("Context C");
 
        if (func->flag & FUNC_USE_CONTEXT)
                WRITE_PARAM("Context C");
 
-       if (func->flag & FUNC_USE_REPORTS)
-               WRITE_PARAM("void *reports");
-
        for (dp = dfunc->cont.properties.first; dp; dp = dp->next) {
                int type, flag, pout;
                const char *ptrstr;
        for (dp = dfunc->cont.properties.first; dp; dp = dp->next) {
                int type, flag, pout;
                const char *ptrstr;
@@ -1740,6 +1837,8 @@ static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *srna, Func
 
                if (type == PROP_POINTER)
                        ptrstr = "";
 
                if (type == PROP_POINTER)
                        ptrstr = "";
+               else if ((type == PROP_POINTER) && (flag & PROP_RNAPTR) && !(flag & PROP_THICK_WRAP))
+                       ptrstr = "*";
                else if (type == PROP_POINTER || dp->prop->arraydimension)
                        ptrstr = "*";
                else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
                else if (type == PROP_POINTER || dp->prop->arraydimension)
                        ptrstr = "*";
                else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
@@ -1853,10 +1952,13 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
 
                        if (cprop->type)
                        CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
 
                        if (cprop->type)
-                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (const char *)cprop->type, srna->identifier,
-                                       prop->identifier);
+                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s)", (const char *)cprop->type, srna->identifier,
+                                       prop->identifier, (cprop->length ? "TRUE" : "FALSE"),
+                                       (cprop->lookupint ? "TRUE" : "FALSE"), (cprop->lookupstring ? "TRUE" : "FALSE"));
                        else
                        else
-                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
+                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s)", "UnknownType", srna->identifier,
+                                       prop->identifier, (cprop->length ? "TRUE" : "FALSE"),
+                                       (cprop->lookupint ? "TRUE" : "FALSE"), (cprop->lookupstring ? "TRUE" : "FALSE"));
 #endif
                        break;
                }
 #endif
                        break;
                }
@@ -1888,6 +1990,10 @@ static void rna_def_struct_function_call_impl_cpp(FILE *f, StructRNA *srna, Func
                if (dsrna->dnaname) fprintf(f, "(::%s *) this->ptr.data", dsrna->dnaname);
                else fprintf(f, "(::%s *) this->ptr.data", srna->identifier);
        }
                if (dsrna->dnaname) fprintf(f, "(::%s *) this->ptr.data", dsrna->dnaname);
                else fprintf(f, "(::%s *) this->ptr.data", srna->identifier);
        }
+       else if (func->flag & FUNC_USE_SELF_TYPE) {
+               WRITE_COMMA;
+               fprintf(f, "this->ptr.type");
+       }
 
        if (func->flag & FUNC_USE_MAIN)
                WRITE_PARAM("(::Main *) main");
 
        if (func->flag & FUNC_USE_MAIN)
                WRITE_PARAM("(::Main *) main");
@@ -1896,7 +2002,7 @@ static void rna_def_struct_function_call_impl_cpp(FILE *f, StructRNA *srna, Func
                WRITE_PARAM("(::bContext *) C.ptr.data");
 
        if (func->flag & FUNC_USE_REPORTS)
                WRITE_PARAM("(::bContext *) C.ptr.data");
 
        if (func->flag & FUNC_USE_REPORTS)
-               WRITE_PARAM("(::ReportList *) reports");
+               WRITE_PARAM("NULL");
 
        dp = dfunc->cont.properties.first;
        for (; dp; dp = dp->next) {
 
        dp = dfunc->cont.properties.first;
        for (; dp; dp = dp->next) {
@@ -1909,7 +2015,10 @@ static void rna_def_struct_function_call_impl_cpp(FILE *f, StructRNA *srna, Func
                        fprintf(f, "%s_len, ", dp->prop->identifier);
 
                if (dp->prop->type == PROP_POINTER)
                        fprintf(f, "%s_len, ", dp->prop->identifier);
 
                if (dp->prop->type == PROP_POINTER)
-                       fprintf(f, "(::%s *) %s.ptr.data", rna_parameter_type_name(dp->prop), rna_safe_id(dp->prop->identifier));
+                       if ((dp->prop->flag & PROP_RNAPTR) && !(dp->prop->flag & PROP_THICK_WRAP))
+                               fprintf(f, "(::%s *) &%s.ptr", rna_parameter_type_name(dp->prop), rna_safe_id(dp->prop->identifier));
+                       else
+                               fprintf(f, "(::%s *) %s.ptr.data", rna_parameter_type_name(dp->prop), rna_safe_id(dp->prop->identifier));
                else
                        fprintf(f, "%s", rna_safe_id(dp->prop->identifier));
        }
                else
                        fprintf(f, "%s", rna_safe_id(dp->prop->identifier));
        }
@@ -1937,23 +2046,23 @@ static void rna_def_struct_function_impl_cpp(FILE *f, StructRNA *srna, FunctionD
                if (dp->prop->type == PROP_POINTER) {
                        pprop = (PointerPropertyRNA *) dp->prop;
 
                if (dp->prop->type == PROP_POINTER) {
                        pprop = (PointerPropertyRNA *) dp->prop;
 
-                       fprintf(f, "\t\tPointerRNA ptr;\n");
+                       fprintf(f, "\t\tPointerRNA result;\n");
 
                        if ((dp->prop->flag & PROP_RNAPTR) == 0) {
                                StructRNA *ret_srna = rna_find_struct((const char *) pprop->type);
                                fprintf(f, "\t\t::%s *retdata = ", rna_parameter_type_name(dp->prop));
                                rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
                                if (ret_srna->flag & STRUCT_ID)
 
                        if ((dp->prop->flag & PROP_RNAPTR) == 0) {
                                StructRNA *ret_srna = rna_find_struct((const char *) pprop->type);
                                fprintf(f, "\t\t::%s *retdata = ", rna_parameter_type_name(dp->prop));
                                rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
                                if (ret_srna->flag & STRUCT_ID)
-                                       fprintf(f, "\t\tRNA_id_pointer_create((::ID *) retdata, &ptr);\n");
+                                       fprintf(f, "\t\tRNA_id_pointer_create((::ID *) retdata, &result);\n");
                                else
                                else
-                                       fprintf(f, "\t\tRNA_pointer_create(NULL, &RNA_%s, retdata, &ptr);\n", (const char *) pprop->type);
+                                       fprintf(f, "\t\tRNA_pointer_create((::ID *) ptr.id.data, &RNA_%s, retdata, &result);\n", (const char *) pprop->type);
                        }
                        else {
                        }
                        else {
-                               fprintf(f, "\t\tptr = ");
+                               fprintf(f, "\t\tresult = ");
                                rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
                        }
 
                                rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
                        }
 
-                       fprintf(f, "\t\treturn %s(ptr);\n", (const char *) pprop->type);
+                       fprintf(f, "\t\treturn %s(result);\n", (const char *) pprop->type);
                }
                else {
                        fprintf(f, "\t\treturn ");
                }
                else {
                        fprintf(f, "\t\treturn ");
@@ -2008,8 +2117,12 @@ static void rna_def_function_wrapper_funcs(FILE *f, StructDefRNA *dsrna, Functio
        if (func->flag & FUNC_USE_SELF_ID)
                WRITE_PARAM("_selfid");
 
        if (func->flag & FUNC_USE_SELF_ID)
                WRITE_PARAM("_selfid");
 
-       if ((func->flag & FUNC_NO_SELF) == 0)
+       if ((func->flag & FUNC_NO_SELF) == 0) {
                WRITE_PARAM("_self");
                WRITE_PARAM("_self");
+       }
+       else if (func->flag & FUNC_USE_SELF_TYPE) {
+               WRITE_PARAM("_type");
+       }
 
        if (func->flag & FUNC_USE_MAIN)
                WRITE_PARAM("bmain");
 
        if (func->flag & FUNC_USE_MAIN)
                WRITE_PARAM("bmain");
@@ -2070,6 +2183,9 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                if (dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
                else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
        }
                if (dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
                else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
        }
+       else if (func->flag & FUNC_USE_SELF_TYPE) {
+               fprintf(f, "\tstruct StructRNA *_type;\n");
+       }
 
        dparm = dfunc->cont.properties.first;
        for (; dparm; dparm = dparm->next) {
 
        dparm = dfunc->cont.properties.first;
        for (; dparm; dparm = dparm->next) {
@@ -2086,6 +2202,8 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                /* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
                else if (type == PROP_POINTER || dparm->prop->arraydimension)
                        ptrstr = "*";
                /* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
                else if (type == PROP_POINTER || dparm->prop->arraydimension)
                        ptrstr = "*";
+               else if ((type == PROP_POINTER) && (flag & PROP_RNAPTR) && !(flag & PROP_THICK_WRAP))
+                       ptrstr = "*";
                /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack,
                 * but type name for string props is already char*, so leave empty */
                else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
                /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack,
                 * but type name for string props is already char*, so leave empty */
                else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
@@ -2117,6 +2235,9 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                if (dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
                else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
        }
                if (dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
                else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
        }
+       else if (func->flag & FUNC_USE_SELF_TYPE) {
+               fprintf(f, "\t_type= _ptr->type;\n");
+       }
 
        if (has_data) {
                fprintf(f, "\t_data= (char *)_parms->data;\n");
 
        if (has_data) {
                fprintf(f, "\t_data= (char *)_parms->data;\n");
@@ -2137,6 +2258,10 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                                ptrstr = "**";
                                valstr = "*";
                        }
                                ptrstr = "**";
                                valstr = "*";
                        }
+                       else if ((type == PROP_POINTER) && !(flag & PROP_THICK_WRAP)) {
+                               ptrstr = "**";
+                               valstr = "*";
+                       }
                        else if (type == PROP_POINTER || dparm->prop->arraydimension) {
                                ptrstr = "*";
                                valstr = "";
                        else if (type == PROP_POINTER || dparm->prop->arraydimension) {
                                ptrstr = "*";
                                valstr = "";
@@ -2190,6 +2315,11 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                        fprintf(f, "_self");
                        first = 0;
                }
                        fprintf(f, "_self");
                        first = 0;
                }
+               else if (func->flag & FUNC_USE_SELF_TYPE) {
+                       if (!first) fprintf(f, ", ");
+                       fprintf(f, "_type");
+                       first = 0;
+               }
 
                if (func->flag & FUNC_USE_MAIN) {
                        if (!first) fprintf(f, ", ");
 
                if (func->flag & FUNC_USE_MAIN) {
                        if (!first) fprintf(f, ", ");
@@ -2315,7 +2445,6 @@ static const char *rna_property_subtypename(PropertySubType type)
                case PROP_FILENAME: return "PROP_FILENAME";
                case PROP_DIRPATH: return "PROP_DIRPATH";
                case PROP_BYTESTRING: return "PROP_BYTESTRING";
                case PROP_FILENAME: return "PROP_FILENAME";
                case PROP_DIRPATH: return "PROP_DIRPATH";
                case PROP_BYTESTRING: return "PROP_BYTESTRING";
-               case PROP_TRANSLATE: return "PROP_TRANSLATE";
                case PROP_UNSIGNED: return "PROP_UNSIGNED";
                case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
                case PROP_FACTOR: return "PROP_FACTOR";
                case PROP_UNSIGNED: return "PROP_UNSIGNED";
                case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
                case PROP_FACTOR: return "PROP_FACTOR";
@@ -2336,7 +2465,9 @@ static const char *rna_property_subtypename(PropertySubType type)
                case PROP_COORDS: return "PROP_COORDS";
                case PROP_LAYER: return "PROP_LAYER";
                case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
                case PROP_COORDS: return "PROP_COORDS";
                case PROP_LAYER: return "PROP_LAYER";
                case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
-               default: {
+               case PROP_PASSWORD: return "PROP_PASSWORD";
+               default:
+               {
                        /* in case we don't have a type preset that includes the subtype */
                        if (RNA_SUBTYPE_UNIT(type)) {
                                return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
                        /* in case we don't have a type preset that includes the subtype */
                        if (RNA_SUBTYPE_UNIT(type)) {
                                return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
@@ -2502,6 +2633,11 @@ static void rna_generate_static_parameter_prototypes(FILE *f, StructRNA *srna, F
                else fprintf(f, "struct %s *_self", srna->identifier);
                first = 0;
        }
                else fprintf(f, "struct %s *_self", srna->identifier);
                first = 0;
        }
+       else if (func->flag & FUNC_USE_SELF_TYPE) {
+               if (!first) fprintf(f, ", ");
+               fprintf(f, "struct StructRNA *_type");
+               first = 0;
+       }
 
        if (func->flag & FUNC_USE_MAIN) {
                if (!first) fprintf(f, ", ");
 
        if (func->flag & FUNC_USE_MAIN) {
                if (!first) fprintf(f, ", ");
@@ -2771,9 +2907,9 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                rna_property_structname(prop->type),
                srna->identifier, strnest, prop->identifier);
 
                rna_property_structname(prop->type),
                srna->identifier, strnest, prop->identifier);
 
-       if (prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
+       if (prop->next) fprintf(f, "\t{(PropertyRNA *)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
        else fprintf(f, "\t{NULL, ");
        else fprintf(f, "\t{NULL, ");
-       if (prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
+       if (prop->prev) fprintf(f, "(PropertyRNA *)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
        else fprintf(f, "NULL,\n");
        fprintf(f, "\t%d, ", prop->magic);
        rna_print_c_string(f, prop->identifier);
        else fprintf(f, "NULL,\n");
        fprintf(f, "\t%d, ", prop->magic);
        rna_print_c_string(f, prop->identifier);
@@ -2812,11 +2948,15 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_BOOLEAN:
                {
                        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
                case PROP_BOOLEAN:
                {
                        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, %s, %d, ",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, %d, ",
                                rna_function_string(bprop->get),
                                rna_function_string(bprop->set),
                                rna_function_string(bprop->getarray),
                                rna_function_string(bprop->setarray),
                                rna_function_string(bprop->get),
                                rna_function_string(bprop->set),
                                rna_function_string(bprop->getarray),
                                rna_function_string(bprop->setarray),
+                               rna_function_string(bprop->get_ex),
+                               rna_function_string(bprop->set_ex),
+                               rna_function_string(bprop->getarray_ex),
+                               rna_function_string(bprop->setarray_ex),
                                bprop->defaultvalue);
                        if (prop->arraydimension && prop->totarraylength)
                                fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
                                bprop->defaultvalue);
                        if (prop->arraydimension && prop->totarraylength)
                                fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
@@ -2826,12 +2966,17 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_INT:
                {
                        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
                case PROP_INT:
                {
                        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, %s, %s,\n\t",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,\n\t",
                                rna_function_string(iprop->get),
                                rna_function_string(iprop->set),
                                rna_function_string(iprop->getarray),
                                rna_function_string(iprop->setarray),
                                rna_function_string(iprop->get),
                                rna_function_string(iprop->set),
                                rna_function_string(iprop->getarray),
                                rna_function_string(iprop->setarray),
-                               rna_function_string(iprop->range));
+                               rna_function_string(iprop->range),
+                               rna_function_string(iprop->get_ex),
+                               rna_function_string(iprop->set_ex),
+                               rna_function_string(iprop->getarray_ex),
+                               rna_function_string(iprop->setarray_ex),
+                               rna_function_string(iprop->range_ex));
                        rna_int_print(f, iprop->softmin); fprintf(f, ", ");
                        rna_int_print(f, iprop->softmax); fprintf(f, ", ");
                        rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
                        rna_int_print(f, iprop->softmin); fprintf(f, ", ");
                        rna_int_print(f, iprop->softmax); fprintf(f, ", ");
                        rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
@@ -2846,12 +2991,17 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_FLOAT:
                {
                        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
                case PROP_FLOAT:
                {
                        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, %s, %s, ",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, ",
                                rna_function_string(fprop->get),
                                rna_function_string(fprop->set),
                                rna_function_string(fprop->getarray),
                                rna_function_string(fprop->setarray),
                                rna_function_string(fprop->get),
                                rna_function_string(fprop->set),
                                rna_function_string(fprop->getarray),
                                rna_function_string(fprop->setarray),
-                               rna_function_string(fprop->range));
+                               rna_function_string(fprop->range),
+                               rna_function_string(fprop->get_ex),
+                               rna_function_string(fprop->set_ex),
+                               rna_function_string(fprop->getarray_ex),
+                               rna_function_string(fprop->setarray_ex),
+                               rna_function_string(fprop->range_ex));
                        rna_float_print(f, fprop->softmin); fprintf(f, ", ");
                        rna_float_print(f, fprop->softmax); fprintf(f, ", ");
                        rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
                        rna_float_print(f, fprop->softmin); fprintf(f, ", ");
                        rna_float_print(f, fprop->softmax); fprintf(f, ", ");
                        rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
@@ -2867,10 +3017,13 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_STRING:
                {
                        StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
                case PROP_STRING:
                {
                        StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, %d, ",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, %s, %d, ",
                                rna_function_string(sprop->get),
                                rna_function_string(sprop->length),
                                rna_function_string(sprop->set),
                                rna_function_string(sprop->get),
                                rna_function_string(sprop->length),
                                rna_function_string(sprop->set),
+                               rna_function_string(sprop->get_ex),
+                               rna_function_string(sprop->length_ex),
+                               rna_function_string(sprop->set_ex),
                                sprop->maxlength);
                        rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
                        break;
                                sprop->maxlength);
                        rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
                        break;
@@ -2878,10 +3031,12 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_ENUM:
                {
                        EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
                case PROP_ENUM:
                {
                        EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, NULL, ",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, NULL, ",
                                rna_function_string(eprop->get),
                                rna_function_string(eprop->set),
                                rna_function_string(eprop->get),
                                rna_function_string(eprop->set),
-                               rna_function_string(eprop->itemf));
+                               rna_function_string(eprop->itemf),
+                               rna_function_string(eprop->get_ex),
+                               rna_function_string(eprop->set_ex));
                        if (eprop->item)
                                fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
                        else
                        if (eprop->item)
                                fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
                        else
@@ -2945,12 +3100,12 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
                fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
 
                if (func->cont.next)
                fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
 
                if (func->cont.next)
-                       fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier,
+                       fprintf(f, "\t{(FunctionRNA *)&rna_%s_%s_func, ", srna->identifier,
                                ((FunctionRNA *)func->cont.next)->identifier);
                else
                        fprintf(f, "\t{NULL, ");
                if (func->cont.prev)
                                ((FunctionRNA *)func->cont.next)->identifier);
                else
                        fprintf(f, "\t{NULL, ");
                if (func->cont.prev)
-                       fprintf(f, "(FunctionRNA*)&rna_%s_%s_func,\n", srna->identifier,
+                       fprintf(f, "(FunctionRNA *)&rna_%s_%s_func,\n", srna->identifier,
                                ((FunctionRNA *)func->cont.prev)->identifier);
                else
                        fprintf(f, "NULL,\n");
                                ((FunctionRNA *)func->cont.prev)->identifier);
                else
                        fprintf(f, "NULL,\n");
@@ -2958,11 +3113,11 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
                fprintf(f, "\tNULL,\n");
 
                parm = func->cont.properties.first;
                fprintf(f, "\tNULL,\n");
 
                parm = func->cont.properties.first;
-               if (parm) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
+               if (parm) fprintf(f, "\t{(PropertyRNA *)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
                else fprintf(f, "\t{NULL, ");
 
                parm = func->cont.properties.last;
                else fprintf(f, "\t{NULL, ");
 
                parm = func->cont.properties.last;
-               if (parm) fprintf(f, "(PropertyRNA*)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
+               if (parm) fprintf(f, "(PropertyRNA *)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
                else fprintf(f, "NULL}},\n");
 
                fprintf(f, "\t");
                else fprintf(f, "NULL}},\n");
 
                fprintf(f, "\t");
@@ -2975,7 +3130,7 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
                else fprintf(f, "\tNULL,\n");
 
                if (func->c_ret)
                else fprintf(f, "\tNULL,\n");
 
                if (func->c_ret)
-                       fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
+                       fprintf(f, "\t(PropertyRNA *)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
                else
                        fprintf(f, "\tNULL\n");
 
                else
                        fprintf(f, "\tNULL\n");
 
@@ -2993,11 +3148,11 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
        fprintf(f, "\tNULL,\n");
 
        prop = srna->cont.properties.first;
        fprintf(f, "\tNULL,\n");
 
        prop = srna->cont.properties.first;
-       if (prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
+       if (prop) fprintf(f, "\t{(PropertyRNA *)&rna_%s_%s, ", srna->identifier, prop->identifier);
        else fprintf(f, "\t{NULL, ");
 
        prop = srna->cont.properties.last;
        else fprintf(f, "\t{NULL, ");
 
        prop = srna->cont.properties.last;
-       if (prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
+       if (prop) fprintf(f, "(PropertyRNA *)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
        else fprintf(f, "NULL}},\n");
        fprintf(f, "\t");
        rna_print_c_string(f, srna->identifier);
        else fprintf(f, "NULL}},\n");
        fprintf(f, "\t");
        rna_print_c_string(f, srna->identifier);
@@ -3016,7 +3171,7 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
                while (base->base && base->base->nameproperty == prop)
                        base = base->base;
 
                while (base->base && base->base->nameproperty == prop)
                        base = base->base;
 
-               fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", base->identifier, prop->identifier);
+               fprintf(f, "\t(PropertyRNA *)&rna_%s_%s, ", base->identifier, prop->identifier);
        }
        else fprintf(f, "\tNULL, ");
 
        }
        else fprintf(f, "\tNULL, ");
 
@@ -3024,7 +3179,7 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
        base = srna;
        while (base->base && base->base->iteratorproperty == prop)
                base = base->base;
        base = srna;
        while (base->base && base->base->iteratorproperty == prop)
                base = base->base;
-       fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", base->identifier);
+       fprintf(f, "(PropertyRNA *)&rna_%s_rna_properties,\n", base->identifier);
 
        if (srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
        else fprintf(f, "\tNULL,\n");
 
        if (srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
        else fprintf(f, "\tNULL,\n");
@@ -3046,11 +3201,11 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
        }
 
        func = srna->functions.first;
        }
 
        func = srna->functions.first;
-       if (func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, func->identifier);
+       if (func) fprintf(f, "\t{(FunctionRNA *)&rna_%s_%s_func, ", srna->identifier, func->identifier);
        else fprintf(f, "\t{NULL, ");
 
        func = srna->functions.last;
        else fprintf(f, "\t{NULL, ");
 
        func = srna->functions.last;
-       if (func) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
+       if (func) fprintf(f, "(FunctionRNA *)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
        else fprintf(f, "NULL}\n");
 
        fprintf(f, "};\n");
        else fprintf(f, "NULL}\n");
 
        fprintf(f, "};\n");
@@ -3094,7 +3249,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
        {"rna_main.c", "rna_main_api.c", RNA_def_main},
        {"rna_material.c", "rna_material_api.c", RNA_def_material},
        {"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
        {"rna_main.c", "rna_main_api.c", RNA_def_main},
        {"rna_material.c", "rna_material_api.c", RNA_def_material},
        {"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
-       {"rna_meta.c", NULL, RNA_def_meta},
+       {"rna_meta.c", "rna_meta_api.c", RNA_def_meta},
        {"rna_modifier.c", NULL, RNA_def_modifier},
        {"rna_nla.c", NULL, RNA_def_nla},
        {"rna_nodetree.c", NULL, RNA_def_nodetree},
        {"rna_modifier.c", NULL, RNA_def_modifier},
        {"rna_nla.c", NULL, RNA_def_nla},
        {"rna_nodetree.c", NULL, RNA_def_nodetree},
@@ -3105,6 +3260,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
        {"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
        {"rna_property.c", NULL, RNA_def_gameproperty},
        {"rna_render.c", NULL, RNA_def_render},
        {"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
        {"rna_property.c", NULL, RNA_def_gameproperty},
        {"rna_render.c", NULL, RNA_def_render},
+       {"rna_rigidbody.c", NULL, RNA_def_rigidbody},
        {"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
        {"rna_screen.c", NULL, RNA_def_screen},
        {"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
        {"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
        {"rna_screen.c", NULL, RNA_def_screen},
        {"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
@@ -3146,6 +3302,8 @@ static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const
        fprintf(f, "#include <string.h>\n\n");
        fprintf(f, "#include <stddef.h>\n\n");
 
        fprintf(f, "#include <string.h>\n\n");
        fprintf(f, "#include <stddef.h>\n\n");
 
+       fprintf(f, "#include \"MEM_guardedalloc.h\"\n\n");
+
        fprintf(f, "#include \"DNA_ID.h\"\n");
        fprintf(f, "#include \"DNA_scene_types.h\"\n");
 
        fprintf(f, "#include \"DNA_ID.h\"\n");
        fprintf(f, "#include \"DNA_scene_types.h\"\n");
 
@@ -3270,7 +3428,7 @@ static const char *cpp_classes = ""
 "namespace BL {\n"
 "\n"
 "#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
 "namespace BL {\n"
 "\n"
 "#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
-"      inline bool sname::identifier(void) { return sname##_##identifier##_get(&ptr)? true: false; } \\\n"
+"      inline bool sname::identifier(void) { return sname##_##identifier##_get(&ptr) ? true: false; } \\\n"
 "      inline void sname::identifier(int value) { sname##_##identifier##_set(&ptr, value); }\n"
 "\n"
 "#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
 "      inline void sname::identifier(int value) { sname##_##identifier##_set(&ptr, value); }\n"
 "\n"
 "#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
@@ -3338,21 +3496,98 @@ static const char *cpp_classes = ""
 "              int len= sname##_##identifier##_length(&ptr); \\\n"
 "              std::string str; str.resize(len); \\\n"
 "              sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
 "              int len= sname##_##identifier##_length(&ptr); \\\n"
 "              std::string str; str.resize(len); \\\n"
 "              sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
+"      inline void sname::identifier(const std::string& value) { \\\n"
+"              sname##_##identifier##_set(&ptr, value.c_str()); } \\\n"
 "\n"
 "#define POINTER_PROPERTY(type, sname, identifier) \\\n"
 "      inline type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
 "\n"
 "\n"
 "#define POINTER_PROPERTY(type, sname, identifier) \\\n"
 "      inline type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
 "\n"
-"#define COLLECTION_PROPERTY(type, sname, identifier) \\\n"
+"#define COLLECTION_PROPERTY_LENGTH_FALSE(sname, identifier) \\\n"
+"      inline static int sname##_##identifier##_length_wrap(PointerRNA *ptr) \\\n"
+"      { \\\n"
+"              CollectionPropertyIterator iter; \\\n"
+"              int length = 0; \\\n"
+"              sname##_##identifier##_begin(&iter, ptr); \\\n"
+"              while (iter.valid) { \\\n"
+"                      sname##_##identifier##_next(&iter); \\\n"
+"                      ++length; \\\n"
+"              } \\\n"
+"              sname##_##identifier##_end(&iter); \\\n"
+"              return length; \\\n"
+"      } \n"
+"#define COLLECTION_PROPERTY_LENGTH_TRUE(sname, identifier) \\\n"
+"      inline static int sname##_##identifier##_length_wrap(PointerRNA *ptr) \\\n"
+"      { return sname##_##identifier##_length(ptr); } \n"
+"\n"
+"#define COLLECTION_PROPERTY_LOOKUP_INT_FALSE(sname, identifier) \\\n"
+"      inline static int sname##_##identifier##_lookup_int_wrap(PointerRNA *ptr, int key, PointerRNA *r_ptr) \\\n"
+"      { \\\n"
+"              CollectionPropertyIterator iter; \\\n"
+"              int i = 0, found = 0; \\\n"
+"              sname##_##identifier##_begin(&iter, ptr); \\\n"
+"              while (iter.valid) { \\\n"
+"                      if (i == key) { \\\n"
+"                              *r_ptr = iter.ptr; \\\n"
+"                              found = 1; \\\n"
+"                              break; \\\n"
+"                      } \\\n"
+"                      sname##_##identifier##_next(&iter); \\\n"
+"                      ++i; \\\n"
+"              } \\\n"
+"              sname##_##identifier##_end(&iter); \\\n"
+"              if (!found) \\\n"
+"                      memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
+"              return found; \\\n"
+"      } \n"
+"#define COLLECTION_PROPERTY_LOOKUP_INT_TRUE(sname, identifier) \\\n"
+"      inline static int sname##_##identifier##_lookup_int_wrap(PointerRNA *ptr, int key, PointerRNA *r_ptr) \\\n"
+"      { return sname##_##identifier##_lookup_int(ptr, key, r_ptr); } \n"
+"\n"
+"#define COLLECTION_PROPERTY_LOOKUP_STRING_FALSE(sname, identifier) \\\n"
+"      inline static int sname##_##identifier##_lookup_string_wrap(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) \\\n"
+"      { \\\n"
+"              CollectionPropertyIterator iter; \\\n"
+"              int found = 0; \\\n"
+"              PropertyRNA *item_name_prop = RNA_struct_name_property(ptr->type); \\\n"
+"              sname##_##identifier##_begin(&iter, ptr); \\\n"
+"              while (iter.valid && !found) { \\\n"
+"                      char name_fixed[32]; \\\n"
+"                      const char *name; \\\n"
+"                      int name_length; \\\n"
+"                      name = RNA_property_string_get_alloc(&iter.ptr, item_name_prop, name_fixed, sizeof(name_fixed), &name_length); \\\n"
+"                      if (!strncmp(name, key, name_length)) { \\\n"
+"                              *r_ptr = iter.ptr; \\\n"
+"                              found = 1; \\\n"
+"                      } \\\n"
+"                      if (name_fixed != name) \\\n"
+"                              MEM_freeN((void *) name); \\\n"
+"                      sname##_##identifier##_next(&iter); \\\n"
+"              } \\\n"
+"              sname##_##identifier##_end(&iter); \\\n"
+"              if (!found) \\\n"
+"                      memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
+"              return found; \\\n"
+"      } \n"
+"#define COLLECTION_PROPERTY_LOOKUP_STRING_TRUE(sname, identifier) \\\n"
+"      inline static int sname##_##identifier##_lookup_string_wrap(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) \\\n"
+"      { return sname##_##identifier##_lookup_string(ptr, key, r_ptr); } \n"
+"\n"
+"#define COLLECTION_PROPERTY(collection_funcs, type, sname, identifier, has_length, has_lookup_int, has_lookup_string) \\\n"
 "      typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
 "              sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
 "      typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
 "              sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
+"      COLLECTION_PROPERTY_LENGTH_##has_length(sname, identifier) \\\n"
+"      COLLECTION_PROPERTY_LOOKUP_INT_##has_lookup_int(sname, identifier) \\\n"
+"      COLLECTION_PROPERTY_LOOKUP_STRING_##has_lookup_string(sname, identifier) \\\n"
 "      Collection<sname, type, sname##_##identifier##_begin, \\\n"
 "      Collection<sname, type, sname##_##identifier##_begin, \\\n"
-"              sname##_##identifier##_next, sname##_##identifier##_end> identifier;\n"
+"              sname##_##identifier##_next, sname##_##identifier##_end, \\\n"
+"              sname##_##identifier##_length_wrap, \\\n"
+"              sname##_##identifier##_lookup_int_wrap, sname##_##identifier##_lookup_string_wrap, collection_funcs> identifier;\n"
 "\n"
 "class Pointer {\n"
 "public:\n"
 "      Pointer(const PointerRNA &p) : ptr(p) { }\n"
 "      operator const PointerRNA&() { return ptr; }\n"
 "\n"
 "class Pointer {\n"
 "public:\n"
 "      Pointer(const PointerRNA &p) : ptr(p) { }\n"
 "      operator const PointerRNA&() { return ptr; }\n"
-"      bool is_a(StructRNA *type) { return RNA_struct_is_a(ptr.type, type)? true: false; }\n"
+"      bool is_a(StructRNA *type) { return RNA_struct_is_a(ptr.type, type) ? true: false; }\n"
 "      operator void*() { return ptr.data; }\n"
 "      operator bool() { return ptr.data != NULL; }\n"
 "\n"
 "      operator void*() { return ptr.data; }\n"
 "      operator bool() { return ptr.data != NULL; }\n"
 "\n"
@@ -3380,18 +3615,18 @@ static const char *cpp_classes = ""
 "      int length;\n"
 "\n"
 "      DynamicArray() : data(NULL), length(0) {}\n"
 "      int length;\n"
 "\n"
 "      DynamicArray() : data(NULL), length(0) {}\n"
-"      DynamicArray(int new_length) : data(NULL), length(new_length) { data = (float*)malloc(sizeof(T) * new_length); }\n"
+"      DynamicArray(int new_length) : data(NULL), length(new_length) { data = (float *)malloc(sizeof(T) * new_length); }\n"
 "      DynamicArray(const DynamicArray<T>& other) { copy_from(other); }\n"
 "      const DynamicArray<T>& operator=(const DynamicArray<T>& other) { copy_from(other); return *this; }\n"
 "\n"
 "      DynamicArray(const DynamicArray<T>& other) { copy_from(other); }\n"
 "      const DynamicArray<T>& operator=(const DynamicArray<T>& other) { copy_from(other); return *this; }\n"
 "\n"
-"      ~DynamicArray() { if(data) free(data); }\n"
+"      ~DynamicArray() { if (data) free(data); }\n"
 "\n"
 "      operator T*() { return data; }\n"
 "\n"
 "protected:\n"
 "      void copy_from(const DynamicArray<T>& other) {\n"
 "\n"
 "      operator T*() { return data; }\n"
 "\n"
 "protected:\n"
 "      void copy_from(const DynamicArray<T>& other) {\n"
-"              if(data) free(data);\n"
-"              data = (float*)malloc(sizeof(T) * other.length);\n"
+"              if (data) free(data);\n"
+"              data = (float *)malloc(sizeof(T) * other.length);\n"
 "              memcpy(data, other.data, sizeof(T) * other.length);\n"
 "              length = other.length;\n"
 "      }\n"
 "              memcpy(data, other.data, sizeof(T) * other.length);\n"
 "              length = other.length;\n"
 "      }\n"
@@ -3400,6 +3635,9 @@ static const char *cpp_classes = ""
 "typedef void (*TBeginFunc)(CollectionPropertyIterator *iter, PointerRNA *ptr);\n"
 "typedef void (*TNextFunc)(CollectionPropertyIterator *iter);\n"
 "typedef void (*TEndFunc)(CollectionPropertyIterator *iter);\n"
 "typedef void (*TBeginFunc)(CollectionPropertyIterator *iter, PointerRNA *ptr);\n"
 "typedef void (*TNextFunc)(CollectionPropertyIterator *iter);\n"
 "typedef void (*TEndFunc)(CollectionPropertyIterator *iter);\n"
+"typedef int (*TLengthFunc)(PointerRNA *ptr);\n"
+"typedef int (*TLookupIntFunc)(PointerRNA *ptr, int key, PointerRNA *r_ptr);\n"
+"typedef int (*TLookupStringFunc)(PointerRNA *ptr, const char *key, PointerRNA *r_ptr);\n"
 "\n"
 "template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
 "class CollectionIterator {\n"
 "\n"
 "template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
 "class CollectionIterator {\n"
@@ -3419,7 +3657,7 @@ static const char *cpp_classes = ""
 "{ return iter.valid != other.iter.valid; }\n"
 "\n"
 "      void begin(const Pointer &ptr)\n"
 "{ return iter.valid != other.iter.valid; }\n"
 "\n"
 "      void begin(const Pointer &ptr)\n"
-"      { if (init) Tend(&iter); Tbegin(&iter, (PointerRNA*)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
+"      { if (init) Tend(&iter); Tbegin(&iter, (PointerRNA *)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
 "\n"
 "private:\n"
 "      const CollectionIterator<T, Tbegin, Tnext, Tend>& operator="
 "\n"
 "private:\n"
 "      const CollectionIterator<T, Tbegin, Tnext, Tend>& operator="
@@ -3430,27 +3668,97 @@ static const char *cpp_classes = ""
 "      bool init;\n"
 "};\n"
 "\n"
 "      bool init;\n"
 "};\n"
 "\n"
-"template<typename Tp, typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
-"class Collection {\n"
+"template<typename Tp, typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend,\n"
+"         TLengthFunc Tlength, TLookupIntFunc Tlookup_int, TLookupStringFunc Tlookup_string,\n"
+"         typename Tcollection_funcs>\n"
+"class Collection : public Tcollection_funcs {\n"
 "public:\n"
 "public:\n"
-"      Collection(const PointerRNA &p) : ptr(p) {}\n"
+"      Collection(const PointerRNA &p) : Tcollection_funcs(p), ptr(p)  {}\n"
 "\n"
 "      void begin(CollectionIterator<T, Tbegin, Tnext, Tend>& iter)\n"
 "      { iter.begin(ptr); }\n"
 "      CollectionIterator<T, Tbegin, Tnext, Tend> end()\n"
 "      { return CollectionIterator<T, Tbegin, Tnext, Tend>(); } /* test */ \n"
 "\n"
 "      void begin(CollectionIterator<T, Tbegin, Tnext, Tend>& iter)\n"
 "      { iter.begin(ptr); }\n"
 "      CollectionIterator<T, Tbegin, Tnext, Tend> end()\n"
 "      { return CollectionIterator<T, Tbegin, Tnext, Tend>(); } /* test */ \n"
+""
+"      int length()\n"
+"      { return Tlength(&ptr); }\n"
+"      T operator[](int key)\n"
+"      { PointerRNA r_ptr; Tlookup_int(&ptr, key, &r_ptr); return T(r_ptr); }\n"
+"      T operator[](const std::string &key)\n"
+"      { PointerRNA r_ptr; Tlookup_string(&ptr, key.c_str(), &r_ptr); return T(r_ptr); }\n"
 "\n"
 "private:\n"
 "      PointerRNA ptr;\n"
 "};\n"
 "\n"
 "private:\n"
 "      PointerRNA ptr;\n"
 "};\n"
+"\n"
+"class DefaultCollectionFunctions {\n"
+"public:\n"
+"      DefaultCollectionFunctions(const PointerRNA &p) {}\n"
+"};\n"
+"\n"
 "\n";
 
 "\n";
 
+static int rna_is_collection_prop(PropertyRNA *prop)
+{
+       if (!(prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN)))
+               if (prop->type == PROP_COLLECTION)
+                       return 1;
+
+       return 0;
+}
+
+static int rna_is_collection_functions_struct(const char **collection_structs, const char *struct_name)
+{
+       int a = 0, found = 0;
+
+       while (collection_structs[a]) {
+               if (!strcmp(collection_structs[a], struct_name)) {
+                       found = 1;
+                       break;
+               }
+               a++;
+       }
+
+       return found;
+}
+
+static void rna_generate_header_class_cpp(StructDefRNA *ds, FILE *f)
+{
+       StructRNA *srna = ds->srna;
+       PropertyDefRNA *dp;
+       FunctionDefRNA *dfunc;
+
+       fprintf(f, "/**************** %s ****************/\n\n", srna->name);
+
+       fprintf(f, "class %s : public %s {\n", srna->identifier, (srna->base) ? srna->base->identifier : "Pointer");
+       fprintf(f, "public:\n");
+       fprintf(f, "\t%s(const PointerRNA &ptr_arg) :\n\t\t%s(ptr_arg)", srna->identifier,
+               (srna->base) ? srna->base->identifier : "Pointer");
+       for (dp = ds->cont.properties.first; dp; dp = dp->next)
+               if (rna_is_collection_prop(dp->prop))
+                       fprintf(f, ",\n\t\t%s(ptr_arg)", dp->prop->identifier);
+       fprintf(f, "\n\t\t{}\n\n");
+
+       for (dp = ds->cont.properties.first; dp; dp = dp->next)
+               rna_def_property_funcs_header_cpp(f, ds->srna, dp);
+
+       fprintf(f, "\n");
+       for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next)
+               rna_def_struct_function_header_cpp(f, srna, dfunc);
+
+       fprintf(f, "};\n\n");
+}
+
 static void rna_generate_header_cpp(BlenderRNA *UNUSED(brna), FILE *f)
 {
        StructDefRNA *ds;
        PropertyDefRNA *dp;
        StructRNA *srna;
        FunctionDefRNA *dfunc;
 static void rna_generate_header_cpp(BlenderRNA *UNUSED(brna), FILE *f)
 {
        StructDefRNA *ds;
        PropertyDefRNA *dp;
        StructRNA *srna;
        FunctionDefRNA *dfunc;
+       const char *first_collection_func_struct = NULL;
+       const char *collection_func_structs[256] = {NULL};
+       int all_collection_func_structs = 0;
+       int max_collection_func_structs = sizeof(collection_func_structs) / sizeof(collection_func_structs[0]) - 1;
 
        fprintf(f, "\n#ifndef __RNA_BLENDER_CPP_H__\n");
        fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
 
        fprintf(f, "\n#ifndef __RNA_BLENDER_CPP_H__\n");
        fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
@@ -3467,33 +3775,59 @@ static void rna_generate_header_cpp(BlenderRNA *UNUSED(brna), FILE *f)
 
        fprintf(f, "/**************** Declarations ****************/\n\n");
 
 
        fprintf(f, "/**************** Declarations ****************/\n\n");
 
-       for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
+       for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
                fprintf(f, "class %s;\n", ds->srna->identifier);
                fprintf(f, "class %s;\n", ds->srna->identifier);
+       }
        fprintf(f, "\n");
 
        fprintf(f, "\n");
 
+       /* first get list of all structures used as collection functions, so they'll be declared first */
        for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
        for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
-               srna = ds->srna;
+               for (dp = ds->cont.properties.first; dp; dp = dp->next) {
+                       if (rna_is_collection_prop(dp->prop)) {
+                               PropertyRNA *prop = dp->prop;
+
+                               if (prop->srna) {
+                                       /* store name of structure which first uses custom functions for collections */
+                                       if (first_collection_func_struct == NULL)
+                                               first_collection_func_struct = ds->srna->identifier;
+
+                                       if (!rna_is_collection_functions_struct(collection_func_structs, (char *)prop->srna)) {
+                                               if (all_collection_func_structs >= max_collection_func_structs) {
+                                                       printf("Array size to store all collection structures names is too small\n");
+                                                       exit(1);
+                                               }
 
 
-               fprintf(f, "/**************** %s ****************/\n\n", srna->name);
+                                               collection_func_structs[all_collection_func_structs++] = (char *)prop->srna;
+                                       }
+                               }
+                       }
+               }
+       }
 
 
-               fprintf(f, "class %s : public %s {\n", srna->identifier, (srna->base) ? srna->base->identifier : "Pointer");
-               fprintf(f, "public:\n");
-               fprintf(f, "\t%s(const PointerRNA &ptr_arg) :\n\t\t%s(ptr_arg)", srna->identifier,
-                       (srna->base) ? srna->base->identifier : "Pointer");
-               for (dp = ds->cont.properties.first; dp; dp = dp->next)
-                       if (!(dp->prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN)))
-                               if (dp->prop->type == PROP_COLLECTION)
-                                       fprintf(f, ",\n\t\t%s(ptr_arg)", dp->prop->identifier);
-               fprintf(f, "\n\t\t{}\n\n");
+       /* declare all structures in such order:
+        * - first N structures which doesn't use custom functions for collections
+        * - all structures used for custom functions in collections
+        * - all the rest structures
+        * such an order prevents usage of non-declared classes
+        */
+       for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
+               srna = ds->srna;
 
 
-               for (dp = ds->cont.properties.first; dp; dp = dp->next)
-                       rna_def_property_funcs_header_cpp(f, ds->srna, dp);
+               if (!strcmp(srna->identifier, first_collection_func_struct)) {
+                       StructDefRNA *ds2;
+                       StructRNA *srna2;
 
 
-               fprintf(f, "\n");
-               for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next)
-                       rna_def_struct_function_header_cpp(f, srna, dfunc);
+                       for (ds2 = DefRNA.structs.first; ds2; ds2 = ds2->cont.next) {
+                               srna2 = ds2->srna;
+
+                               if (rna_is_collection_functions_struct(collection_func_structs, srna2->identifier)) {
+                                       rna_generate_header_class_cpp(ds2, f);
+                               }
+                       }
+               }
 
 
-               fprintf(f, "};\n\n");
+               if (!rna_is_collection_functions_struct(collection_func_structs, srna->identifier))
+                       rna_generate_header_class_cpp(ds, f);
        }
 
        fprintf(f, "} /* namespace BL */\n");
        }
 
        fprintf(f, "} /* namespace BL */\n");
@@ -3549,6 +3883,13 @@ static int rna_preprocess(const char *outfile)
                if (PROCESS_ITEMS[i].define) {
                        PROCESS_ITEMS[i].define(brna);
 
                if (PROCESS_ITEMS[i].define) {
                        PROCESS_ITEMS[i].define(brna);
 
+                       /* sanity check */
+                       if (!DefRNA.animate) {
+                               fprintf(stderr,
+                                       "Error: DefRNA.animate left disabled in %s\n",
+                                       PROCESS_ITEMS[i].filename);
+                       }
+
                        for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
                                if (!ds->filename)
                                        ds->filename = PROCESS_ITEMS[i].filename;
                        for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
                                if (!ds->filename)
                                        ds->filename = PROCESS_ITEMS[i].filename;
@@ -3557,34 +3898,8 @@ static int rna_preprocess(const char *outfile)
 
        rna_auto_types();
 
 
        rna_auto_types();
 
-
-       /* create RNA_blender_cpp.h */
-       strcpy(deffile, outfile);
-       strcat(deffile, "RNA_blender_cpp.h" TMP_EXT);
-
        status = (DefRNA.error != 0);
 
        status = (DefRNA.error != 0);
 
-       if (status) {
-               make_bad_file(deffile, __LINE__);
-       }
-       else {
-               file = fopen(deffile, "w");
-
-               if (!file) {
-                       fprintf(stderr, "Unable to open file: %s\n", deffile);
-                       status = 1;
-               }
-               else {
-                       rna_generate_header_cpp(brna, file);
-                       fclose(file);
-                       status = (DefRNA.error != 0);
-               }
-       }
-
-       replace_if_different(deffile, NULL);
-
-       rna_sort(brna);
-
        /* create rna_gen_*.c files */
        for (i = 0; PROCESS_ITEMS[i].filename; i++) {
                strcpy(deffile, outfile);
        /* create rna_gen_*.c files */
        for (i = 0; PROCESS_ITEMS[i].filename; i++) {
                strcpy(deffile, outfile);
@@ -3617,6 +3932,31 @@ static int rna_preprocess(const char *outfile)
                replace_if_different(deffile, deps);
        }
 
                replace_if_different(deffile, deps);
        }
 
+       /* create RNA_blender_cpp.h */
+       strcpy(deffile, outfile);
+       strcat(deffile, "RNA_blender_cpp.h" TMP_EXT);
+
+       if (status) {
+               make_bad_file(deffile, __LINE__);
+       }
+       else {
+               file = fopen(deffile, "w");
+
+               if (!file) {
+                       fprintf(stderr, "Unable to open file: %s\n", deffile);
+                       status = 1;
+               }
+               else {
+                       rna_generate_header_cpp(brna, file);
+                       fclose(file);
+                       status = (DefRNA.error != 0);
+               }
+       }
+
+       replace_if_different(deffile, NULL);
+
+       rna_sort(brna);
+
        /* create RNA_blender.h */
        strcpy(deffile, outfile);
        strcat(deffile, "RNA_blender.h" TMP_EXT);
        /* create RNA_blender.h */
        strcpy(deffile, outfile);
        strcat(deffile, "RNA_blender.h" TMP_EXT);