@@ -121,6 +121,7 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False):
121
121
include_gen_folder / "variant" / "builtin_binds.hpp" ,
122
122
include_gen_folder / "variant" / "utility_functions.hpp" ,
123
123
include_gen_folder / "variant" / "variant_size.hpp" ,
124
+ include_gen_folder / "variant" / "builtin_vararg_methods.hpp" ,
124
125
include_gen_folder / "classes" / "global_constants.hpp" ,
125
126
include_gen_folder / "classes" / "global_constants_binds.hpp" ,
126
127
]:
@@ -344,6 +345,40 @@ def generate_builtin_bindings(api, output_dir, build_config):
344
345
345
346
builtin_binds_file .write ("\n " .join (builtin_binds ))
346
347
348
+ # Create a header to implement all builtin class vararg methods and be included in "variant.hpp".
349
+ builtin_vararg_methods_header = include_gen_folder / "builtin_vararg_methods.hpp"
350
+ builtin_vararg_methods_header .open ("w+" ).write (
351
+ generate_builtin_class_vararg_method_implements_header (api ["builtin_classes" ])
352
+ )
353
+
354
+
355
+ def generate_builtin_class_vararg_method_implements_header (builtin_classes ):
356
+ result = []
357
+
358
+ add_header ("builtin_vararg_methods.hpp" , result )
359
+
360
+ header_guard = "GODOT_CPP_BUILTIN_VARARG_METHODS_HPP"
361
+ result .append (f"#ifndef { header_guard } " )
362
+ result .append (f"#define { header_guard } " )
363
+ result .append ("" )
364
+ for builtin_api in builtin_classes :
365
+ if not "methods" in builtin_api :
366
+ continue
367
+ class_name = builtin_api ["name" ]
368
+ for method in builtin_api ["methods" ]:
369
+ if not method ["is_vararg" ]:
370
+ continue
371
+
372
+ result += make_varargs_template (
373
+ method , "is_static" in method and method ["is_static" ], class_name , False , False , True
374
+ )
375
+ result .append ("" )
376
+
377
+ result .append ("" )
378
+ result .append (f"#endif // ! { header_guard } " )
379
+
380
+ return "\n " .join (result )
381
+
347
382
348
383
def generate_builtin_class_header (builtin_api , size , used_classes , fully_used_classes ):
349
384
result = []
@@ -1969,10 +2004,22 @@ def make_signature(
1969
2004
return function_signature
1970
2005
1971
2006
1972
- def make_varargs_template (function_data , static = False ):
2007
+ def make_varargs_template (
2008
+ function_data ,
2009
+ static = False ,
2010
+ class_befor_signature = "" ,
2011
+ with_public_declare = True ,
2012
+ with_indent = True ,
2013
+ for_builtin_classes = False ,
2014
+ ):
1973
2015
result = []
1974
2016
1975
- function_signature = "\t public: template<class... Args> "
2017
+ function_signature = ""
2018
+
2019
+ if with_public_declare :
2020
+ function_signature = "public: "
2021
+
2022
+ function_signature += "template<class... Args> "
1976
2023
1977
2024
if static :
1978
2025
function_signature += "static "
@@ -1993,6 +2040,8 @@ def make_varargs_template(function_data, static=False):
1993
2040
if not function_signature .endswith ("*" ):
1994
2041
function_signature += " "
1995
2042
2043
+ if len (class_befor_signature ) > 0 :
2044
+ function_signature += class_befor_signature + "::"
1996
2045
function_signature += f'{ escape_identifier (function_data ["name" ])} '
1997
2046
1998
2047
method_arguments = []
@@ -2013,7 +2062,7 @@ def make_varargs_template(function_data, static=False):
2013
2062
function_signature += " {"
2014
2063
result .append (function_signature )
2015
2064
2016
- args_array = f"\t \ t std::array<Variant, { len (method_arguments )} + sizeof...(Args)> variant_args {{ "
2065
+ args_array = f"\t std::array<Variant, { len (method_arguments )} + sizeof...(Args)> variant_args {{ "
2017
2066
for argument in method_arguments :
2018
2067
if argument ["type" ] == "Variant" :
2019
2068
args_array += argument ["name" ]
@@ -2023,19 +2072,42 @@ def make_varargs_template(function_data, static=False):
2023
2072
2024
2073
args_array += "Variant(args)... };"
2025
2074
result .append (args_array )
2026
- result .append (f"\t \ t std::array<const Variant *, { len (method_arguments )} + sizeof...(Args)> call_args;" )
2027
- result .append ("\t \ t for(size_t i = 0; i < variant_args.size(); i++) {" )
2028
- result .append ("\t \t \ t call_args[i] = &variant_args[i];" )
2029
- result .append ("\t \t }" )
2075
+ result .append (f"\t std::array<const Variant *, { len (method_arguments )} + sizeof...(Args)> call_args;" )
2076
+ result .append ("\t for(size_t i = 0; i < variant_args.size(); i++) {" )
2077
+ result .append ("\t \t call_args[i] = &variant_args[i];" )
2078
+ result .append ("\t }" )
2030
2079
2031
- call_line = "\t \t "
2080
+ call_line = "\t "
2032
2081
2033
- if return_type != "void" :
2034
- call_line += "return "
2082
+ if not for_builtin_classes :
2083
+ if return_type != "void" :
2084
+ call_line += "return "
2035
2085
2036
- call_line += f'{ escape_identifier (function_data ["name" ])} _internal(call_args.data(), variant_args.size());'
2037
- result .append (call_line )
2038
- result .append ("\t }" )
2086
+ call_line += f'{ escape_identifier (function_data ["name" ])} _internal(call_args.data(), variant_args.size());'
2087
+ result .append (call_line )
2088
+ else :
2089
+ base = "(GDExtensionTypePtr)&opaque"
2090
+ if static :
2091
+ base = "nullptr"
2092
+
2093
+ ret = "nullptr"
2094
+ if return_type != "void" :
2095
+ ret = "&ret"
2096
+ result .append (f'\t { correct_type (function_data ["return_type" ])} ret;' )
2097
+
2098
+ function_name = function_data ["name" ]
2099
+ result .append (
2100
+ f"\t _method_bindings.method_{ function_name } ({ base } , reinterpret_cast<GDExtensionConstTypePtr *>(call_args.data()), { ret } , { len (method_arguments )} + sizeof...(Args));"
2101
+ )
2102
+
2103
+ if return_type != "void" :
2104
+ result .append ("\t return ret;" )
2105
+
2106
+ result .append ("}" )
2107
+
2108
+ if with_indent :
2109
+ for i in range (len (result )):
2110
+ result [i ] = "\t " + result [i ]
2039
2111
2040
2112
return result
2041
2113
0 commit comments