diff --git a/source/blender/makesrna/intern/makesrna.cc b/source/blender/makesrna/intern/makesrna.cc index 983b267a08c..e629578f746 100644 --- a/source/blender/makesrna/intern/makesrna.cc +++ b/source/blender/makesrna/intern/makesrna.cc @@ -3010,6 +3010,25 @@ static void rna_def_property_wrapper_funcs(FILE *f, StructDefRNA *dsrna, Propert } } +/** + * Counts the number of template arguments by looking at `<` and `,` characters in the name. More + * complex template arguments that contains `,` themselves are not handled yet. + */ +static int count_template_args(const char *function_name) +{ + BLI_assert(function_name != nullptr); + if (!strstr(function_name, "<")) { + return 0; + } + int count = 1; + for (const char *c = function_name; *c; c++) { + if (*c == ',') { + count++; + } + } + return count; +} + static void rna_def_function_wrapper_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc) { StructRNA *srna = dsrna->srna; @@ -3026,7 +3045,10 @@ static void rna_def_function_wrapper_funcs(FILE *f, StructDefRNA *dsrna, Functio rna_construct_wrapper_function_name( funcname, sizeof(funcname), srna->identifier, func->identifier, "func"); - fprintf(f, "RNA_EXTERN_C "); + /* A function with templates cannot have C linkage. */ + if (!(dfunc->call && count_template_args(dfunc->call) > 0)) { + fprintf(f, "RNA_EXTERN_C "); + } rna_generate_static_parameter_prototypes(f, srna, dfunc, funcname, 0); fprintf(f, "\n{\n"); @@ -3785,6 +3807,19 @@ static void rna_generate_static_parameter_prototypes(FILE *f, dsrna = rna_find_struct_def(srna); func = dfunc->func; + const int template_args_num = dfunc->call ? count_template_args(dfunc->call) : 0; + if (!name_override && template_args_num > 0) { + /* The template names are called A, B, C, etc. */ + BLI_assert(template_args_num <= 26); + fprintf(f, "template "); + } + /* return type */ LISTBASE_FOREACH (PropertyDefRNA *, dparm, &dfunc->cont.properties) { if (dparm->prop == func->c_ret) { @@ -3810,7 +3845,15 @@ static void rna_generate_static_parameter_prototypes(FILE *f, /* function name */ if (name_override == nullptr || name_override[0] == '\0') { - fprintf(f, "%s(", dfunc->call); + /* Here we only need the function name without the template parameters. */ + const char *template_begin = strstr(dfunc->call, "<"); + if (template_begin) { + const int num_chars = template_begin - dfunc->call; + fprintf(f, "%.*s(", num_chars, dfunc->call); + } + else { + fprintf(f, "%s(", dfunc->call); + } } else { fprintf(f, "%s(", name_override);