RNA: review of commits in the past days, check the diffs for the
[blender.git] / source / blender / makesrna / intern / rna_define.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): Blender Foundation (2008).
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <float.h>
26 #include <limits.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "MEM_guardedalloc.h"
32
33 #include "DNA_genfile.h"
34 #include "DNA_sdna_types.h"
35
36 #include "RNA_access.h"
37 #include "RNA_define.h"
38 #include "RNA_types.h"
39
40 #include "rna_internal.h"
41
42 /* Global used during defining */
43
44 BlenderDefRNA DefRNA = {0, {0, 0}, {0, 0}, 0, 0, 0};
45
46 /* Duplicated code since we can't link in blenkernel or blenlib */
47
48 #ifndef MIN2
49 #define MIN2(x,y) ((x)<(y)? (x): (y))
50 #define MAX2(x,y) ((x)>(y)? (x): (y))
51 #endif
52
53 void rna_addtail(ListBase *listbase, void *vlink)
54 {
55         Link *link= vlink;
56
57         link->next = NULL;
58         link->prev = listbase->last;
59
60         if (listbase->last) ((Link *)listbase->last)->next = link;
61         if (listbase->first == 0) listbase->first = link;
62         listbase->last = link;
63 }
64
65 void rna_remlink(ListBase *listbase, void *vlink)
66 {
67         Link *link= vlink;
68
69         if (link->next) link->next->prev = link->prev;
70         if (link->prev) link->prev->next = link->next;
71
72         if (listbase->last == link) listbase->last = link->prev;
73         if (listbase->first == link) listbase->first = link->next;
74 }
75
76 void rna_freelinkN(ListBase *listbase, void *vlink)
77 {
78         rna_remlink(listbase, vlink);
79         MEM_freeN(vlink);
80 }
81
82 void rna_freelistN(ListBase *listbase)
83 {
84         Link *link, *next;
85         
86         for(link=listbase->first; link; link=next) {
87                 next= link->next;
88                 MEM_freeN(link);
89         }
90         
91         listbase->first= listbase->last= NULL;
92 }
93
94 /* DNA utility function for looking up members */
95
96 typedef struct DNAStructMember {
97         char *type;
98         char *name;
99         int arraylength;
100         int pointerlevel;
101 } DNAStructMember;
102
103 static int rna_member_cmp(const char *name, const char *oname)
104 {
105         int a=0;
106         
107         /* compare without pointer or array part */
108         while(name[0]=='*')
109                 name++;
110         while(oname[0]=='*')
111                 oname++;
112         
113         while(1) {
114                 if(name[a]=='[' && oname[a]==0) return 1;
115                 if(name[a]==0) break;
116                 if(name[a] != oname[a]) return 0;
117                 a++;
118         }
119         if(name[a]==0 && oname[a] == '.') return 2;
120         if(name[a]==0 && oname[a] == '-' && oname[a+1] == '>') return 3;
121
122         return (name[a] == oname[a]);
123 }
124
125 static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *membername, DNAStructMember *smember)
126 {
127         char *dnaname;
128         short *sp;
129         int a, b, structnr, totmember, cmp;
130
131         structnr= DNA_struct_find_nr(sdna, structname);
132         if(structnr == -1)
133                 return 0;
134
135         sp= sdna->structs[structnr];
136         totmember= sp[1];
137         sp+= 2;
138
139         for(a=0; a<totmember; a++, sp+=2) {
140                 dnaname= sdna->names[sp[1]];
141
142                 cmp= rna_member_cmp(dnaname, membername);
143
144                 if(cmp == 1) {
145                         smember->type= sdna->types[sp[0]];
146                         smember->name= dnaname;
147                         smember->arraylength= DNA_elem_array_size(smember->name, strlen(smember->name));
148
149                         smember->pointerlevel= 0;
150                         for(b=0; dnaname[b] == '*'; b++)
151                                 smember->pointerlevel++;
152
153                         return 1;
154                 }
155                 else if(cmp == 2) {
156                         membername= strstr(membername, ".") + strlen(".");
157                         return rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
158                 }
159                 else if(cmp == 3) {
160                         membername= strstr(membername, "->") + strlen("->");
161                         return rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
162                 }
163         }
164
165         return 0;
166 }
167
168 /* Blender Data Definition */
169
170 BlenderRNA *RNA_create()
171 {
172         BlenderRNA *brna;
173
174         brna= MEM_callocN(sizeof(BlenderRNA), "BlenderRNA");
175
176         DefRNA.sdna= DNA_sdna_from_data(DNAstr,  DNAlen, 0);
177         DefRNA.structs.first= DefRNA.structs.last= NULL;
178         DefRNA.error= 0;
179         DefRNA.preprocess= 1;
180
181         return brna;
182 }
183
184 void RNA_define_free(BlenderRNA *brna)
185 {
186         StructDefRNA *srna;
187         AllocDefRNA *alloc;
188
189         for(alloc=DefRNA.allocs.first; alloc; alloc=alloc->next)
190                 MEM_freeN(alloc->mem);
191         rna_freelistN(&DefRNA.allocs);
192
193         for(srna=DefRNA.structs.first; srna; srna=srna->next)
194                 rna_freelistN(&srna->properties);
195
196         rna_freelistN(&DefRNA.structs);
197
198         if(DefRNA.sdna) {
199                 DNA_sdna_free(DefRNA.sdna);
200                 DefRNA.sdna= NULL;
201         }
202
203         DefRNA.error= 0;
204 }
205
206 void RNA_free(BlenderRNA *brna)
207 {
208         StructRNA *srna, *nextsrna;
209         PropertyRNA *prop, *nextprop;
210
211         if(DefRNA.preprocess) {
212                 RNA_define_free(brna);
213
214                 for(srna=brna->structs.first; srna; srna=srna->next)
215                         rna_freelistN(&srna->properties);
216
217                 rna_freelistN(&brna->structs);
218                 
219                 MEM_freeN(brna);
220         }
221         else {
222                 for(srna=brna->structs.first; srna; srna=nextsrna) {
223                         nextsrna= srna->next;
224
225                         for(prop=srna->properties.first; prop; prop=nextprop) {
226                                 nextprop= prop->next;
227
228                                 if(prop->flag & PROP_RUNTIME)
229                                         rna_freelinkN(&srna->properties, prop);
230                         }
231
232                         if(srna->flag & STRUCT_RUNTIME)
233                                 rna_freelinkN(&brna->structs, srna);
234                 }
235         }
236 }
237
238 static size_t rna_property_type_sizeof(PropertyType type)
239 {
240         switch(type) {
241                 case PROP_BOOLEAN: return sizeof(BooleanPropertyRNA);
242                 case PROP_INT: return sizeof(IntPropertyRNA);
243                 case PROP_FLOAT: return sizeof(FloatPropertyRNA);
244                 case PROP_STRING: return sizeof(StringPropertyRNA);
245                 case PROP_ENUM: return sizeof(EnumPropertyRNA);
246                 case PROP_POINTER: return sizeof(PointerPropertyRNA);
247                 case PROP_COLLECTION: return sizeof(CollectionPropertyRNA);
248                 default: return 0;
249         }
250 }
251
252 static StructDefRNA *rna_find_def_struct(StructRNA *srna)
253 {
254         StructDefRNA *ds;
255
256         for(ds=DefRNA.structs.first; ds; ds=ds->next)
257                 if(ds->srna == srna)
258                         return ds;
259
260         return NULL;
261 }
262
263 static PropertyDefRNA *rna_find_def_property(StructRNA *srna, PropertyRNA *prop)
264 {
265         StructDefRNA *ds= rna_find_def_struct(srna);
266         PropertyDefRNA *dp;
267
268         if(ds)
269                 for(dp=ds->properties.first; dp; dp=dp->next)
270                         if(dp->prop == prop)
271                                 return dp;
272         
273         return NULL;
274 }
275
276 /* Struct Definition */
277
278 StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from, const char *name)
279 {
280         StructRNA *srna, *srnafrom= NULL;
281         StructDefRNA *ds= NULL, *dsfrom= NULL;
282         PropertyRNA *prop, *propfrom;
283
284         if(from) {
285                 /* find struct to derive from */
286                 for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->next)
287                         if(strcmp(srnafrom->identifier, from) == 0)
288                                 break;
289
290                 if(!srnafrom) {
291                         fprintf(stderr, "RNA_def_struct: struct %s not found to define %s.\n", from, identifier);
292                         DefRNA.error= 1;
293                 }
294         }
295
296         srna= MEM_callocN(sizeof(StructRNA), "StructRNA");
297         DefRNA.laststruct= srna;
298
299         if(srnafrom) {
300                 /* copy from struct to derive stuff, a bit clumsy since we can't
301                  * use MEM_dupallocN, data structs may not be alloced but builtin */
302                 memcpy(srna, srnafrom, sizeof(StructRNA));
303                 srna->properties.first= srna->properties.last= NULL;
304
305                 if(DefRNA.preprocess) {
306                         srna->from= (StructRNA*)from;
307                         dsfrom= rna_find_def_struct(srnafrom);
308                 }
309                 else
310                         srna->from= srnafrom;
311         }
312
313         srna->identifier= identifier;
314         srna->name= name;
315
316         rna_addtail(&brna->structs, srna);
317
318         if(DefRNA.preprocess) {
319                 ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
320                 ds->srna= srna;
321                 rna_addtail(&DefRNA.structs, ds);
322
323                 if(dsfrom)
324                         ds->dnafromname= dsfrom->dnaname;
325         }
326
327         /* in preprocess, try to find sdna */
328         if(DefRNA.preprocess)
329                 RNA_def_struct_sdna(srna, srna->identifier);
330         else
331                 srna->flag |= STRUCT_RUNTIME;
332
333         if(srnafrom) {
334                 /* copy from struct to derive stuff, a bit clumsy since we can't
335                  * use MEM_dupallocN, data structs may not be alloced but builtin */
336
337                 for(propfrom= srnafrom->properties.first; propfrom; propfrom=propfrom->next) {
338                         prop= RNA_def_property(srna, propfrom->identifier, propfrom->type, propfrom->subtype);
339
340                         rna_remlink(&srna->properties, prop);
341                         memcpy(prop, propfrom, rna_property_type_sizeof(propfrom->type));
342
343                         if(!DefRNA.preprocess)
344                                 prop->flag |= PROP_RUNTIME;
345
346                         prop->next= prop->prev= NULL;
347                         rna_addtail(&srna->properties, prop);
348
349                         if(propfrom == srnafrom->nameproperty)
350                                 srna->nameproperty= prop;
351                         if(propfrom == srnafrom->iteratorproperty)
352                                 srna->iteratorproperty= prop;
353
354                         if(DefRNA.preprocess) {
355                                 PropertyDefRNA *dp, *dpfrom;
356                                 
357                                 dp= ds->properties.last;
358                                 dpfrom= rna_find_def_property(srnafrom, propfrom);
359
360                                 rna_remlink(&ds->properties, dp);
361                                 memcpy(dp, dpfrom, sizeof(*dp));
362                                 dp->srna= srna;
363                                 dp->prop= prop;
364                                 dp->next= dp->prev= NULL;
365                                 rna_addtail(&ds->properties, dp);
366                         }
367                 }
368         }
369         else {
370                 /* define some builtin properties */
371                 prop= RNA_def_property(srna, "rna_properties", PROP_COLLECTION, PROP_NONE);
372                 RNA_def_property_flag(prop, PROP_BUILTIN);
373                 RNA_def_property_ui_text(prop, "Properties", "RNA property collection.");
374
375                 if(DefRNA.preprocess) {
376                         RNA_def_property_struct_type(prop, "Property");
377                         RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", "rna_iterator_listbase_end", "rna_builtin_properties_get", 0, 0, 0, 0);
378                 }
379                 else {
380 #ifdef RNA_RUNTIME
381                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
382                         cprop->begin= rna_builtin_properties_begin;
383                         cprop->next= rna_builtin_properties_next;
384                         cprop->next= rna_iterator_listbase_end;
385                         cprop->get= rna_builtin_properties_get;
386                         cprop->structtype= &RNA_Property;
387 #endif
388                 }
389
390                 prop= RNA_def_property(srna, "rna_type", PROP_POINTER, PROP_NONE);
391                 RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
392                 RNA_def_property_ui_text(prop, "RNA", "RNA type definition.");
393
394                 if(DefRNA.preprocess) {
395                         RNA_def_property_struct_type(prop, "Struct");
396                         RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL);
397                 }
398                 else {
399 #ifdef RNA_RUNTIME
400                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
401                         pprop->get= rna_builtin_type_get;
402                         pprop->structtype= &RNA_Struct;
403 #endif
404                 }
405         }
406
407         return srna;
408 }
409
410 void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
411 {
412         StructDefRNA *ds= DefRNA.structs.last;
413
414         if(!DefRNA.preprocess) {
415                 fprintf(stderr, "RNA_def_struct_sdna: only during preprocessing.\n");
416                 return;
417         }
418
419         if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
420                 if(!DefRNA.silent) {
421                         fprintf(stderr, "RNA_def_struct_sdna: %s not found.\n", structname);
422                         DefRNA.error= 1;
423                 }
424                 return;
425         }
426
427         ds->dnaname= structname;
428 }
429
430 void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
431 {
432         StructDefRNA *ds= DefRNA.structs.last;
433
434         if(!DefRNA.preprocess) {
435                 fprintf(stderr, "RNA_def_struct_sdna_from: only during preprocessing.\n");
436                 return;
437         }
438
439         if(!ds->dnaname) {
440                 fprintf(stderr, "RNA_def_struct_sdna_from: %s base struct must know DNA already.\n", structname);
441                 return;
442         }
443
444         if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
445                 if(!DefRNA.silent) {
446                         fprintf(stderr, "RNA_def_struct_sdna_from: %s not found.\n", structname);
447                         DefRNA.error= 1;
448                 }
449                 return;
450         }
451
452         ds->dnafromprop= propname;
453         ds->dnaname= structname;
454 }
455
456 void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
457 {
458         if(prop->type != PROP_STRING) {
459                 fprintf(stderr, "RNA_def_struct_name_property: %s.%s, must be a string property.\n", srna->identifier, prop->identifier);
460                 DefRNA.error= 1;
461         }
462         else
463                 srna->nameproperty= prop;
464 }
465
466 void RNA_def_struct_flag(StructRNA *srna, int flag)
467 {
468         srna->flag= flag;
469 }
470
471 void RNA_def_struct_funcs(StructRNA *srna, const char *notify, const char *refine)
472 {
473         if(!DefRNA.preprocess) {
474                 fprintf(stderr, "RNA_def_struct_funcs: only during preprocessing.\n");
475                 return;
476         }
477
478         if(notify) srna->notify= (NotifyFunc)notify;
479         if(refine) srna->refine= (StructRefineFunc)refine;
480 }
481
482
483 void RNA_def_struct_identifier(StructRNA *srna, const char *identifier, const char *name)
484 {
485         if(DefRNA.preprocess) {
486                 fprintf(stderr, "RNA_def_struct_name_runtime: only at runtime.\n");
487                 return;
488         }
489
490         srna->identifier= identifier;
491         srna->name= name;
492 }
493
494 /* Property Definition */
495
496 PropertyRNA *RNA_def_property(StructRNA *srna, const char *identifier, int type, int subtype)
497 {
498         StructDefRNA *ds;
499         PropertyDefRNA *dp= NULL;
500         PropertyRNA *prop;
501
502         if(DefRNA.preprocess) {
503                 ds= DefRNA.structs.last;
504                 dp= MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA");
505                 rna_addtail(&ds->properties, dp);
506         }
507
508         prop= MEM_callocN(rna_property_type_sizeof(type), "PropertyRNA");
509
510         switch(type) {
511                 case PROP_BOOLEAN:
512                         break;
513                 case PROP_INT: {
514                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
515
516                         iprop->hardmin= (subtype == PROP_UNSIGNED)? 0: INT_MIN;
517                         iprop->hardmax= INT_MAX;
518
519                         iprop->softmin= (subtype == PROP_UNSIGNED)? 0: -10000; /* rather arbitrary .. */
520                         iprop->softmax= 10000;
521                         iprop->step= 1;
522                         break;
523                 }
524                 case PROP_FLOAT: {
525                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
526
527                         fprop->hardmin= (subtype == PROP_UNSIGNED)? 0.0f: -FLT_MAX;
528                         fprop->hardmax= FLT_MAX;
529
530                         fprop->softmin= (subtype == PROP_UNSIGNED)? 0.0f: -10000.0f; /* rather arbitrary .. */
531                         fprop->softmax= 10000.0f;
532                         fprop->step= 10;
533                         fprop->precision= 3;
534                         break;
535                 }
536                 case PROP_STRING: {
537                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
538
539                         sprop->defaultvalue= "";
540                         sprop->maxlength= 0;
541                         break;
542                 }
543                 case PROP_ENUM:
544                 case PROP_POINTER:
545                 case PROP_COLLECTION:
546                         break;
547                 default:
548                         fprintf(stderr, "RNA_def_property: %s.%s, invalid property type.\n", srna->identifier, identifier);
549                         DefRNA.error= 1;
550                         return NULL;
551         }
552
553         if(DefRNA.preprocess) {
554                 dp->srna= srna;
555                 dp->prop= prop;
556         }
557
558         prop->magic= RNA_MAGIC;
559         prop->identifier= identifier;
560         prop->type= type;
561         prop->subtype= subtype;
562         prop->name= identifier;
563         prop->description= "";
564
565         if(type == PROP_COLLECTION || type == PROP_POINTER)
566                 prop->flag= PROP_NOT_EDITABLE|PROP_NOT_DRIVEABLE;
567
568         if(DefRNA.preprocess) {
569                 switch(type) {
570                         case PROP_BOOLEAN:
571                                 DefRNA.silent= 1;
572                                 RNA_def_property_boolean_sdna(prop, NULL, identifier, 0);
573                                 DefRNA.silent= 0;
574                                 break;
575                         case PROP_INT: {
576                                 DefRNA.silent= 1;
577                                 RNA_def_property_int_sdna(prop, NULL, identifier);
578                                 DefRNA.silent= 0;
579                                 break;
580                         }
581                         case PROP_FLOAT: {
582                                 DefRNA.silent= 1;
583                                 RNA_def_property_float_sdna(prop, NULL, identifier);
584                                 DefRNA.silent= 0;
585                                 break;
586                         }
587                         case PROP_STRING: {
588                                 DefRNA.silent= 1;
589                                 RNA_def_property_string_sdna(prop, NULL, identifier);
590                                 DefRNA.silent= 0;
591                                 break;
592                         }
593                         case PROP_ENUM:
594                                 DefRNA.silent= 1;
595                                 RNA_def_property_enum_sdna(prop, NULL, identifier, 0);
596                                 DefRNA.silent= 0;
597                                 break;
598                         case PROP_POINTER:
599                                 DefRNA.silent= 1;
600                                 RNA_def_property_pointer_sdna(prop, NULL, identifier);
601                                 DefRNA.silent= 0;
602                                 break;
603                         case PROP_COLLECTION:
604                                 DefRNA.silent= 1;
605                                 RNA_def_property_collection_sdna(prop, NULL, identifier, NULL);
606                                 DefRNA.silent= 0;
607                                 break;
608                 }
609         }
610         else
611                 prop->flag |= PROP_IDPROPERTY|PROP_RUNTIME;
612
613         rna_addtail(&srna->properties, prop);
614
615         return prop;
616 }
617
618 void RNA_def_property_flag(PropertyRNA *prop, int flag)
619 {
620 #if 0
621         StructRNA *srna;
622 #endif
623
624         prop->flag |= flag;
625
626 #if 0
627         if(prop->type != PROP_POINTER && prop->type != PROP_COLLECTION) {
628                 if(flag & (PROP_EVALUATE_DEPENDENCY|PROP_INVERSE_EVALUATE_DEPENDENCY|PROP_RENDER_DEPENDENCY|PROP_INVERSE_RENDER_DEPENDENCY)) {
629                         fprintf(stderr, "RNA_def_property_flag: %s.%s, only pointer and collection types can create dependencies.\n", ds->srna->identifier, prop->identifier);
630                         DefRNA.error= 1;
631                 }
632         }
633 #endif
634 }
635
636 void RNA_def_property_array(PropertyRNA *prop, int arraylength)
637 {
638         StructRNA *srna= DefRNA.laststruct;
639
640         switch(prop->type) {
641                 case PROP_BOOLEAN:
642                 case PROP_INT:
643                 case PROP_FLOAT:
644                         prop->arraylength= arraylength;
645                         break;
646                 default:
647                         fprintf(stderr, "RNA_def_property_array: %s.%s, only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
648                         DefRNA.error= 1;
649                         break;
650         }
651 }
652
653 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
654 {
655         prop->name= name;
656         prop->description= description;
657 }
658
659 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
660 {
661         StructRNA *srna= DefRNA.laststruct;
662
663         switch(prop->type) {
664                 case PROP_INT: {
665                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
666                         iprop->softmin= (int)min;
667                         iprop->softmax= (int)max;
668                         iprop->step= (int)step;
669                         break;
670                 }
671                 case PROP_FLOAT: {
672                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
673                         fprop->softmin= (float)min;
674                         fprop->softmax= (float)max;
675                         fprop->step= (float)step;
676                         fprop->precision= (int)precision;
677                         break;
678                 }
679                 default:
680                         fprintf(stderr, "RNA_def_property_ui_range: %s.%s, invalid type for ui range.\n", srna->identifier, prop->identifier);
681                         DefRNA.error= 1;
682                         break;
683         }
684 }
685
686 void RNA_def_property_range(PropertyRNA *prop, double min, double max)
687 {
688         StructRNA *srna= DefRNA.laststruct;
689
690         switch(prop->type) {
691                 case PROP_INT: {
692                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
693                         iprop->hardmin= (int)min;
694                         iprop->hardmax= (int)max;
695                         iprop->softmin= MAX2((int)min, iprop->hardmin);
696                         iprop->softmax= MIN2((int)max, iprop->hardmax);
697                         break;
698                 }
699                 case PROP_FLOAT: {
700                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
701                         fprop->hardmin= (float)min;
702                         fprop->hardmax= (float)max;
703                         fprop->softmin= MAX2((float)min, fprop->hardmin);
704                         fprop->softmax= MIN2((float)max, fprop->hardmax);
705                         break;
706                 }
707                 default:
708                         fprintf(stderr, "RNA_def_property_range: %s.%s, invalid type for range.\n", srna->identifier, prop->identifier);
709                         DefRNA.error= 1;
710                         break;
711         }
712 }
713
714 void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
715 {
716         StructRNA *srna= DefRNA.laststruct;
717
718         if(!DefRNA.preprocess) {
719                 fprintf(stderr, "RNA_def_property_struct_type: only during preprocessing.\n");
720                 return;
721         }
722
723         switch(prop->type) {
724                 case PROP_POINTER: {
725                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
726                         pprop->structtype = (StructRNA*)type;
727                         break;
728                 }
729                 case PROP_COLLECTION: {
730                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
731                         cprop->structtype = (StructRNA*)type;
732                         break;
733                 }
734                 default:
735                         fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier);
736                         DefRNA.error= 1;
737                         break;
738         }
739 }
740
741 void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
742 {
743         StructRNA *srna= DefRNA.laststruct;
744         int i;
745
746         switch(prop->type) {
747                 case PROP_ENUM: {
748                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
749                         eprop->item= item;
750                         eprop->totitem= 0;
751                         for(i=0; item[i].identifier; i++)
752                                 eprop->totitem++;
753
754                         break;
755                 }
756                 default:
757                         fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier);
758                         DefRNA.error= 1;
759                         break;
760         }
761 }
762
763 void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
764 {
765         StructRNA *srna= DefRNA.laststruct;
766
767         switch(prop->type) {
768                 case PROP_STRING: {
769                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
770                         sprop->maxlength= maxlength;
771                         break;
772                 }
773                 default:
774                         fprintf(stderr, "RNA_def_property_string_maxlength: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
775                         DefRNA.error= 1;
776                         break;
777         }
778 }
779
780 void RNA_def_property_boolean_default(PropertyRNA *prop, int value)
781 {
782         StructRNA *srna= DefRNA.laststruct;
783
784         switch(prop->type) {
785                 case PROP_BOOLEAN: {
786                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
787                         bprop->defaultvalue= value;
788                         break;
789                 }
790                 default:
791                         fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
792                         DefRNA.error= 1;
793                         break;
794         }
795 }
796
797 void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array)
798 {
799         StructRNA *srna= DefRNA.laststruct;
800
801         switch(prop->type) {
802                 case PROP_BOOLEAN: {
803                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
804                         bprop->defaultarray= array;
805                         break;
806                 }
807                 default:
808                         fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
809                         DefRNA.error= 1;
810                         break;
811         }
812 }
813
814 void RNA_def_property_int_default(PropertyRNA *prop, int value)
815 {
816         StructRNA *srna= DefRNA.laststruct;
817
818         switch(prop->type) {
819                 case PROP_INT: {
820                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
821                         iprop->defaultvalue= value;
822                         break;
823                 }
824                 default:
825                         fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
826                         DefRNA.error= 1;
827                         break;
828         }
829 }
830
831 void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
832 {
833         StructRNA *srna= DefRNA.laststruct;
834
835         switch(prop->type) {
836                 case PROP_INT: {
837                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
838                         iprop->defaultarray= array;
839                         break;
840                 }
841                 default:
842                         fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
843                         DefRNA.error= 1;
844                         break;
845         }
846 }
847
848 void RNA_def_property_float_default(PropertyRNA *prop, float value)
849 {
850         StructRNA *srna= DefRNA.laststruct;
851
852         switch(prop->type) {
853                 case PROP_FLOAT: {
854                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
855                         fprop->defaultvalue= value;
856                         break;
857                 }
858                 default:
859                         fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
860                         DefRNA.error= 1;
861                         break;
862         }
863 }
864
865 void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
866 {
867         StructRNA *srna= DefRNA.laststruct;
868
869         switch(prop->type) {
870                 case PROP_FLOAT: {
871                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
872                         fprop->defaultarray= array;
873                         break;
874                 }
875                 default:
876                         fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
877                         DefRNA.error= 1;
878                         break;
879         }
880 }
881
882 void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
883 {
884         StructRNA *srna= DefRNA.laststruct;
885
886         switch(prop->type) {
887                 case PROP_STRING: {
888                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
889                         sprop->defaultvalue= value;
890                         break;
891                 }
892                 default:
893                         fprintf(stderr, "RNA_def_property_string_default: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
894                         DefRNA.error= 1;
895                         break;
896         }
897 }
898
899 void RNA_def_property_enum_default(PropertyRNA *prop, int value)
900 {
901         StructRNA *srna= DefRNA.laststruct;
902
903         switch(prop->type) {
904                 case PROP_ENUM: {
905                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
906                         eprop->defaultvalue= value;
907                         break;
908                 }
909                 default:
910                         fprintf(stderr, "RNA_def_property_enum_default: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
911                         DefRNA.error= 1;
912                         break;
913         }
914 }
915
916 /* SDNA */
917
918 static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *structname, const char *propname)
919 {
920         DNAStructMember smember;
921         StructDefRNA *ds= DefRNA.structs.last;
922         PropertyDefRNA *dp= ds->properties.last;
923
924         if(!structname)
925                 structname= ds->dnaname;
926         if(!propname)
927                 propname= prop->identifier;
928
929         if(!rna_find_sdna_member(DefRNA.sdna, structname, propname, &smember)) {
930                 if(!DefRNA.silent) {
931                         fprintf(stderr, "rna_def_property_sdna: %s.%s not found.\n", structname, propname);
932                         DefRNA.error= 1;
933                 }
934                 return NULL;
935         }
936
937         if(smember.arraylength > 1)
938                 prop->arraylength= smember.arraylength;
939         else
940                 prop->arraylength= 0;
941         
942         dp->dnastructname= structname;
943         dp->dnastructfromname= ds->dnafromname;
944         dp->dnastructfromprop= ds->dnafromprop;
945         dp->dnaname= propname;
946         dp->dnatype= smember.type;
947         dp->dnaarraylength= smember.arraylength;
948         dp->dnapointerlevel= smember.pointerlevel;
949
950         return dp;
951 }
952
953 void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int bit)
954 {
955         PropertyDefRNA *dp;
956         StructRNA *srna= DefRNA.laststruct;
957         
958         if(!DefRNA.preprocess) {
959                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
960                 return;
961         }
962
963         if(prop->type != PROP_BOOLEAN) {
964                 fprintf(stderr, "RNA_def_property_boolean_sdna: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
965                 DefRNA.error= 1;
966                 return;
967         }
968
969         if((dp=rna_def_property_sdna(prop, structname, propname)))
970                 dp->booleanbit= bit;
971 }
972
973 void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
974 {
975         PropertyDefRNA *dp;
976         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
977         StructRNA *srna= DefRNA.laststruct;
978         
979         if(!DefRNA.preprocess) {
980                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
981                 return;
982         }
983
984         if(prop->type != PROP_INT) {
985                 fprintf(stderr, "RNA_def_property_int_sdna: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
986                 DefRNA.error= 1;
987                 return;
988         }
989
990         if((dp= rna_def_property_sdna(prop, structname, propname))) {
991                 /* SDNA doesn't pass us unsigned unfortunately .. */
992                 if(strcmp(dp->dnatype, "char") == 0) {
993                         iprop->hardmin= iprop->softmin= CHAR_MIN;
994                         iprop->hardmax= iprop->softmax= CHAR_MAX;
995                 }
996                 else if(strcmp(dp->dnatype, "short") == 0) {
997                         iprop->hardmin= iprop->softmin= SHRT_MIN;
998                         iprop->hardmax= iprop->softmax= SHRT_MAX;
999                 }
1000                 else if(strcmp(dp->dnatype, "int") == 0) {
1001                         iprop->hardmin= INT_MIN;
1002                         iprop->hardmax= INT_MAX;
1003
1004                         iprop->softmin= -10000; /* rather arbitrary .. */
1005                         iprop->softmax= 10000;
1006                 }
1007
1008                 if(prop->subtype == PROP_UNSIGNED)
1009                         iprop->hardmin= iprop->softmin= 0;
1010         }
1011 }
1012
1013 void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1014 {
1015         StructRNA *srna= DefRNA.laststruct;
1016
1017         if(!DefRNA.preprocess) {
1018                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1019                 return;
1020         }
1021
1022         if(prop->type != PROP_FLOAT) {
1023                 fprintf(stderr, "RNA_def_property_float_sdna: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
1024                 DefRNA.error= 1;
1025                 return;
1026         }
1027
1028         rna_def_property_sdna(prop, structname, propname);
1029 }
1030
1031 void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname, EnumPropertyFlag flag)
1032 {
1033         PropertyDefRNA *dp;
1034         StructRNA *srna= DefRNA.laststruct;
1035         
1036         if(!DefRNA.preprocess) {
1037                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1038                 return;
1039         }
1040
1041         if(prop->type != PROP_ENUM) {
1042                 fprintf(stderr, "RNA_def_property_enum_sdna: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
1043                 DefRNA.error= 1;
1044                 return;
1045         }
1046
1047         if((dp=rna_def_property_sdna(prop, structname, propname))) {
1048                 dp->enumbitflags= (flag & PROP_DEF_ENUM_BITFLAGS);
1049
1050                 if(prop->arraylength) {
1051                         prop->arraylength= 0;
1052                         if(!DefRNA.silent) {
1053                                 fprintf(stderr, "RNA_def_property_enum_sdna: %s.%s, array not supported for enum type.\n", structname, propname);
1054                                 DefRNA.error= 1;
1055                         }
1056                 }
1057         }
1058 }
1059
1060 void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1061 {
1062         PropertyDefRNA *dp;
1063         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1064         StructRNA *srna= DefRNA.laststruct;
1065
1066         if(!DefRNA.preprocess) {
1067                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1068                 return;
1069         }
1070
1071         if(prop->type != PROP_STRING) {
1072                 fprintf(stderr, "RNA_def_property_string_sdna: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1073                 DefRNA.error= 1;
1074                 return;
1075         }
1076
1077         if((dp=rna_def_property_sdna(prop, structname, propname))) {
1078                 if(prop->arraylength) {
1079                         sprop->maxlength= prop->arraylength;
1080                         prop->arraylength= 0;
1081                 }
1082         }
1083 }
1084
1085 void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1086 {
1087         PropertyDefRNA *dp;
1088         StructRNA *srna= DefRNA.laststruct;
1089         
1090         if(!DefRNA.preprocess) {
1091                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1092                 return;
1093         }
1094
1095         if(prop->type != PROP_POINTER) {
1096                 fprintf(stderr, "RNA_def_property_pointer_sdna: %s.%s, type is not pointer.\n", srna->identifier, prop->identifier);
1097                 DefRNA.error= 1;
1098                 return;
1099         }
1100
1101         if((dp=rna_def_property_sdna(prop, structname, propname))) {
1102                 if(prop->arraylength) {
1103                         prop->arraylength= 0;
1104                         if(!DefRNA.silent) {
1105                                 fprintf(stderr, "RNA_def_property_pointer_sdna: %s.%s, array not supported for pointer type.\n", structname, propname);
1106                                 DefRNA.error= 1;
1107                         }
1108                 }
1109         }
1110 }
1111
1112 void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
1113 {
1114         PropertyDefRNA *dp;
1115         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1116         StructRNA *srna= DefRNA.laststruct;
1117
1118         if(!DefRNA.preprocess) {
1119                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1120                 return;
1121         }
1122
1123         if(prop->type != PROP_COLLECTION) {
1124                 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s, type is not collection.\n", srna->identifier, prop->identifier);
1125                 DefRNA.error= 1;
1126                 return;
1127         }
1128
1129         if((dp=rna_def_property_sdna(prop, structname, propname))) {
1130                 if(prop->arraylength && !lengthpropname) {
1131                         prop->arraylength= 0;
1132
1133                         if(!DefRNA.silent) {
1134                                 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s, array of collections not supported.\n", structname, propname);
1135                                 DefRNA.error= 1;
1136                         }
1137                 }
1138
1139                 if(strcmp(dp->dnatype, "ListBase") == 0) {
1140                         cprop->next= (PropCollectionNextFunc)"rna_iterator_listbase_next";
1141                         cprop->get= (PropCollectionGetFunc)"rna_iterator_listbase_get";
1142                         cprop->end= (PropCollectionEndFunc)"rna_iterator_listbase_end";
1143                 }
1144         }
1145
1146         if(dp && lengthpropname) {
1147                 DNAStructMember smember;
1148                 StructDefRNA *ds= DefRNA.structs.last;
1149
1150                 if(!structname)
1151                         structname= ds->dnaname;
1152
1153                 if(lengthpropname[0] == 0 || rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
1154                         if(lengthpropname[0] == 0) {
1155                                 dp->dnalengthfixed= prop->arraylength;
1156                                 prop->arraylength= 0;
1157                         }
1158                         else {
1159                                 dp->dnalengthstructname= structname;
1160                                 dp->dnalengthname= lengthpropname;
1161                         }
1162
1163                         cprop->next= (PropCollectionNextFunc)"rna_iterator_array_next";
1164                         cprop->end= (PropCollectionEndFunc)"rna_iterator_array_end";
1165
1166                         if(dp->dnapointerlevel >= 2) 
1167                                 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_dereference_get";
1168                         else
1169                                 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_get";
1170                 }
1171                 else {
1172                         if(!DefRNA.silent) {
1173                                 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s not found.\n", structname, lengthpropname);
1174                                 DefRNA.error= 1;
1175                         }
1176                 }
1177         }
1178 }
1179
1180 /* Functions */
1181
1182 void RNA_def_property_funcs(PropertyRNA *prop, const char *notify, const char *editable)
1183 {
1184         if(!DefRNA.preprocess) {
1185                 fprintf(stderr, "RNA_def_property_funcs: only during preprocessing.\n");
1186                 return;
1187         }
1188
1189         if(notify) prop->notify= (NotifyFunc)notify;
1190         if(editable) prop->editable= (EditableFunc)editable;
1191 }
1192
1193 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
1194 {
1195         StructRNA *srna= DefRNA.laststruct;
1196
1197         if(!DefRNA.preprocess) {
1198                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1199                 return;
1200         }
1201
1202         switch(prop->type) {
1203                 case PROP_BOOLEAN: {
1204                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1205
1206                         if(prop->arraylength) {
1207                                 if(get) bprop->getarray= (PropBooleanArrayGetFunc)get;
1208                                 if(set) bprop->setarray= (PropBooleanArraySetFunc)set;
1209                         }
1210                         else {
1211                                 if(get) bprop->get= (PropBooleanGetFunc)get;
1212                                 if(set) bprop->set= (PropBooleanSetFunc)set;
1213                         }
1214                         break;
1215                 }
1216                 default:
1217                         fprintf(stderr, "RNA_def_property_boolean_funcs: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
1218                         DefRNA.error= 1;
1219                         break;
1220         }
1221 }
1222
1223 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
1224 {
1225         StructRNA *srna= DefRNA.laststruct;
1226
1227         if(!DefRNA.preprocess) {
1228                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1229                 return;
1230         }
1231
1232         switch(prop->type) {
1233                 case PROP_INT: {
1234                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1235
1236                         if(prop->arraylength) {
1237                                 if(get) iprop->getarray= (PropIntArrayGetFunc)get;
1238                                 if(set) iprop->setarray= (PropIntArraySetFunc)set;
1239                         }
1240                         else {
1241                                 if(get) iprop->get= (PropIntGetFunc)get;
1242                                 if(set) iprop->set= (PropIntSetFunc)set;
1243                         }
1244                         if(range) iprop->range= (PropIntRangeFunc)range;
1245                         break;
1246                 }
1247                 default:
1248                         fprintf(stderr, "RNA_def_property_int_funcs: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
1249                         DefRNA.error= 1;
1250                         break;
1251         }
1252 }
1253
1254 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
1255 {
1256         StructRNA *srna= DefRNA.laststruct;
1257
1258         if(!DefRNA.preprocess) {
1259                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1260                 return;
1261         }
1262
1263         switch(prop->type) {
1264                 case PROP_FLOAT: {
1265                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1266
1267                         if(prop->arraylength) {
1268                                 if(get) fprop->getarray= (PropFloatArrayGetFunc)get;
1269                                 if(set) fprop->setarray= (PropFloatArraySetFunc)set;
1270                         }
1271                         else {
1272                                 if(get) fprop->get= (PropFloatGetFunc)get;
1273                                 if(set) fprop->set= (PropFloatSetFunc)set;
1274                         }
1275                         if(range) fprop->range= (PropFloatRangeFunc)range;
1276                         break;
1277                 }
1278                 default:
1279                         fprintf(stderr, "RNA_def_property_float_funcs: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
1280                         DefRNA.error= 1;
1281                         break;
1282         }
1283 }
1284
1285 void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set)
1286 {
1287         StructRNA *srna= DefRNA.laststruct;
1288
1289         if(!DefRNA.preprocess) {
1290                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1291                 return;
1292         }
1293
1294         switch(prop->type) {
1295                 case PROP_ENUM: {
1296                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1297
1298                         if(get) eprop->get= (PropEnumGetFunc)get;
1299                         if(set) eprop->set= (PropEnumSetFunc)set;
1300                         break;
1301                 }
1302                 default:
1303                         fprintf(stderr, "RNA_def_property_enum_funcs: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
1304                         DefRNA.error= 1;
1305                         break;
1306         }
1307 }
1308
1309 void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
1310 {
1311         StructRNA *srna= DefRNA.laststruct;
1312
1313         if(!DefRNA.preprocess) {
1314                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1315                 return;
1316         }
1317
1318         switch(prop->type) {
1319                 case PROP_STRING: {
1320                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1321
1322                         if(get) sprop->get= (PropStringGetFunc)get;
1323                         if(length) sprop->length= (PropStringLengthFunc)length;
1324                         if(set) sprop->set= (PropStringSetFunc)set;
1325                         break;
1326                 }
1327                 default:
1328                         fprintf(stderr, "RNA_def_property_string_funcs: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1329                         DefRNA.error= 1;
1330                         break;
1331         }
1332 }
1333
1334 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *type, const char *set)
1335 {
1336         StructRNA *srna= DefRNA.laststruct;
1337
1338         if(!DefRNA.preprocess) {
1339                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1340                 return;
1341         }
1342
1343         switch(prop->type) {
1344                 case PROP_POINTER: {
1345                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1346
1347                         if(get) pprop->get= (PropPointerGetFunc)get;
1348                         if(type) pprop->type= (PropPointerTypeFunc)type;
1349                         if(set) pprop->set= (PropPointerSetFunc)set;
1350                         break;
1351                 }
1352                 default:
1353                         fprintf(stderr, "RNA_def_property_pointer_funcs: %s.%s, type is not pointer.\n", srna->identifier, prop->identifier);
1354                         DefRNA.error= 1;
1355                         break;
1356         }
1357 }
1358
1359 void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *type, const char *length, const char *lookupint, const char *lookupstring)
1360 {
1361         StructRNA *srna= DefRNA.laststruct;
1362
1363         if(!DefRNA.preprocess) {
1364                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1365                 return;
1366         }
1367
1368         switch(prop->type) {
1369                 case PROP_COLLECTION: {
1370                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1371
1372                         if(begin) cprop->begin= (PropCollectionBeginFunc)begin;
1373                         if(next) cprop->next= (PropCollectionNextFunc)next;
1374                         if(end) cprop->end= (PropCollectionEndFunc)end;
1375                         if(get) cprop->get= (PropCollectionGetFunc)get;
1376                         if(type) cprop->type= (PropCollectionTypeFunc)type;
1377                         if(length) cprop->length= (PropCollectionLengthFunc)length;
1378                         if(lookupint) cprop->lookupint= (PropCollectionLookupIntFunc)lookupint;
1379                         if(lookupstring) cprop->lookupstring= (PropCollectionLookupStringFunc)lookupstring;
1380                         break;
1381                 }
1382                 default:
1383                         fprintf(stderr, "RNA_def_property_collection_funcs: %s.%s, type is not collection.\n", srna->identifier, prop->identifier);
1384                         DefRNA.error= 1;
1385                         break;
1386         }
1387 }
1388