@@ -413,6 +413,10 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
413
413
if class_name == "PackedVector3Array" :
414
414
result .append ("#include <godot_cpp/variant/vector3.hpp>" )
415
415
416
+ if is_packed_array (class_name ):
417
+ result .append ("#include <godot_cpp/core/error_macros.hpp>" )
418
+ result .append ("#include <initializer_list>" )
419
+
416
420
if class_name == "Array" :
417
421
result .append ("#include <godot_cpp/variant/array_helpers.hpp>" )
418
422
@@ -454,6 +458,8 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
454
458
result .append ("" )
455
459
result .append ("\t static struct _MethodBindings {" )
456
460
461
+ result .append ("\t \t GDExtensionTypeFromVariantConstructorFunc from_variant_constructor;" )
462
+
457
463
if "constructors" in builtin_api :
458
464
for constructor in builtin_api ["constructors" ]:
459
465
result .append (f'\t \t GDExtensionPtrConstructor constructor_{ constructor ["index" ]} ;' )
@@ -494,6 +500,9 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
494
500
result .append ("\t static void init_bindings();" )
495
501
result .append ("\t static void _init_bindings_constructors_destructor();" )
496
502
503
+ result .append ("" )
504
+ result .append (f"\t { class_name } (const Variant *p_variant);" )
505
+
497
506
result .append ("" )
498
507
result .append ("public:" )
499
508
@@ -558,7 +567,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
558
567
559
568
vararg = method ["is_vararg" ]
560
569
if vararg :
561
- result .append ("\t template<class ... Args>" )
570
+ result .append ("\t template<typename ... Args>" )
562
571
563
572
method_signature = "\t "
564
573
if "is_static" in method and method ["is_static" ]:
@@ -588,17 +597,17 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
588
597
589
598
# Special cases.
590
599
if class_name == "String" :
591
- result .append ("\t static String utf8(const char *from, int len = -1);" )
592
- result .append ("\t void parse_utf8(const char *from, int len = -1);" )
593
- result .append ("\t static String utf16(const char16_t *from, int len = -1);" )
594
- result .append ("\t void parse_utf16(const char16_t *from, int len = -1);" )
600
+ result .append ("\t static String utf8(const char *from, int64_t len = -1);" )
601
+ result .append ("\t void parse_utf8(const char *from, int64_t len = -1);" )
602
+ result .append ("\t static String utf16(const char16_t *from, int64_t len = -1);" )
603
+ result .append ("\t void parse_utf16(const char16_t *from, int64_t len = -1);" )
595
604
result .append ("\t CharString utf8() const;" )
596
605
result .append ("\t CharString ascii() const;" )
597
606
result .append ("\t Char16String utf16() const;" )
598
607
result .append ("\t Char32String utf32() const;" )
599
608
result .append ("\t CharWideString wide_string() const;" )
600
609
result .append ("\t static String num_real(double p_num, bool p_trailing = true);" )
601
- result .append ("\t Error resize(int p_size);" )
610
+ result .append ("\t Error resize(int64_t p_size);" )
602
611
603
612
if "members" in builtin_api :
604
613
for member in builtin_api ["members" ]:
@@ -651,13 +660,13 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
651
660
result .append ("\t String &operator+=(const wchar_t *p_str);" )
652
661
result .append ("\t String &operator+=(const char32_t *p_str);" )
653
662
654
- result .append ("\t const char32_t &operator[](int p_index) const;" )
655
- result .append ("\t char32_t &operator[](int p_index);" )
663
+ result .append ("\t const char32_t &operator[](int64_t p_index) const;" )
664
+ result .append ("\t char32_t &operator[](int64_t p_index);" )
656
665
result .append ("\t const char32_t *ptr() const;" )
657
666
result .append ("\t char32_t *ptrw();" )
658
667
659
668
if class_name == "Array" :
660
- result .append ("\t template <class ... Args>" )
669
+ result .append ("\t template <typename ... Args>" )
661
670
result .append ("\t static Array make(Args... args) {" )
662
671
result .append ("\t \t return helpers::append_all(Array(), args...);" )
663
672
result .append ("\t }" )
@@ -670,8 +679,8 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
670
679
return_type = "int32_t"
671
680
elif class_name == "PackedFloat32Array" :
672
681
return_type = "float"
673
- result .append (f"\t const { return_type } &operator[](int p_index) const;" )
674
- result .append (f"\t { return_type } &operator[](int p_index);" )
682
+ result .append (f"\t const { return_type } &operator[](int64_t p_index) const;" )
683
+ result .append (f"\t { return_type } &operator[](int64_t p_index);" )
675
684
result .append (f"\t const { return_type } *ptr() const;" )
676
685
result .append (f"\t { return_type } *ptrw();" )
677
686
iterators = """
@@ -740,10 +749,21 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
740
749
}
741
750
"""
742
751
result .append (iterators .replace ("$TYPE" , return_type ))
752
+ init_list = """
753
+ _FORCE_INLINE_ $CLASS(std::initializer_list<$TYPE> p_init) {
754
+ ERR_FAIL_COND(resize(p_init.size()) != 0);
755
+
756
+ size_t i = 0;
757
+ for (const $TYPE &element : p_init) {
758
+ set(i++, element);
759
+ }
760
+ }
761
+ """
762
+ result .append (init_list .replace ("$TYPE" , return_type ).replace ("$CLASS" , class_name ))
743
763
744
764
if class_name == "Array" :
745
- result .append ("\t const Variant &operator[](int p_index) const;" )
746
- result .append ("\t Variant &operator[](int p_index);" )
765
+ result .append ("\t const Variant &operator[](int64_t p_index) const;" )
766
+ result .append ("\t Variant &operator[](int64_t p_index);" )
747
767
result .append ("\t void set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);" )
748
768
result .append ("\t void _ref(const Array &p_from) const;" )
749
769
@@ -818,6 +838,10 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
818
838
819
839
result .append (f"void { class_name } ::_init_bindings_constructors_destructor() {{" )
820
840
841
+ result .append (
842
+ f"\t _method_bindings.from_variant_constructor = internal::gdextension_interface_get_variant_to_type_constructor({ enum_type_name } );"
843
+ )
844
+
821
845
if "constructors" in builtin_api :
822
846
for constructor in builtin_api ["constructors" ]:
823
847
result .append (
@@ -899,6 +923,11 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
899
923
900
924
copy_constructor_index = - 1
901
925
926
+ result .append (f"{ class_name } ::{ class_name } (const Variant *p_variant) {{" )
927
+ result .append ("\t _method_bindings.from_variant_constructor(&opaque, p_variant->_native_ptr());" )
928
+ result .append ("}" )
929
+ result .append ("" )
930
+
902
931
if "constructors" in builtin_api :
903
932
for constructor in builtin_api ["constructors" ]:
904
933
method_signature = f"{ class_name } ::{ class_name } ("
@@ -964,8 +993,19 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
964
993
result .append (method_signature + "{" )
965
994
966
995
method_call = "\t "
996
+ is_ref = False
997
+
967
998
if "return_type" in method :
968
- method_call += f'return internal::_call_builtin_method_ptr_ret<{ correct_type (method ["return_type" ])} >('
999
+ return_type = method ["return_type" ]
1000
+ if is_enum (return_type ):
1001
+ method_call += f"return ({ get_gdextension_type (correct_type (return_type ))} )internal::_call_builtin_method_ptr_ret<int64_t>("
1002
+ elif is_pod_type (return_type ) or is_variant (return_type ):
1003
+ method_call += f"return internal::_call_builtin_method_ptr_ret<{ get_gdextension_type (correct_type (return_type ))} >("
1004
+ elif is_refcounted (return_type ):
1005
+ method_call += f"return Ref<{ return_type } >::_gde_internal_constructor(internal::_call_builtin_method_ptr_ret_obj<{ return_type } >("
1006
+ is_ref = True
1007
+ else :
1008
+ method_call += f"return internal::_call_builtin_method_ptr_ret_obj<{ return_type } >("
969
1009
else :
970
1010
method_call += "internal::_call_builtin_method_ptr_no_ret("
971
1011
method_call += f'_method_bindings.method_{ method ["name" ]} , '
@@ -986,6 +1026,9 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
986
1026
result += encode
987
1027
arguments .append (arg_name )
988
1028
method_call += ", " .join (arguments )
1029
+
1030
+ if is_ref :
1031
+ method_call += ")" # Close Ref<> constructor.
989
1032
method_call += ");"
990
1033
991
1034
result .append (method_call )
@@ -1384,7 +1427,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
1384
1427
result .append ("protected:" )
1385
1428
# T is the custom class we want to register (from which the call initiates, going up the inheritance chain),
1386
1429
# B is its base class (can be a custom class too, that's why we pass it).
1387
- result .append ("\t template <class T, class B>" )
1430
+ result .append ("\t template <typename T, typename B>" )
1388
1431
result .append ("\t static void register_virtuals() {" )
1389
1432
if class_name != "Object" :
1390
1433
result .append (f"\t \t { inherits } ::register_virtuals<T, B>();" )
@@ -1430,16 +1473,16 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
1430
1473
if class_name == "Object" :
1431
1474
result .append ("" )
1432
1475
1433
- result .append ("\t template<class T>" )
1476
+ result .append ("\t template<typename T>" )
1434
1477
result .append ("\t static T *cast_to(Object *p_object);" )
1435
1478
1436
- result .append ("\t template<class T>" )
1479
+ result .append ("\t template<typename T>" )
1437
1480
result .append ("\t static const T *cast_to(const Object *p_object);" )
1438
1481
1439
1482
result .append ("\t virtual ~Object() = default;" )
1440
1483
1441
1484
elif use_template_get_node and class_name == "Node" :
1442
- result .append ("\t template<class T>" )
1485
+ result .append ("\t template<typename T>" )
1443
1486
result .append (
1444
1487
"\t T *get_node(const NodePath &p_path) const { return Object::cast_to<T>(get_node_internal(p_path)); }"
1445
1488
)
@@ -1696,7 +1739,7 @@ def generate_global_constants(api, output_dir):
1696
1739
header .append ("" )
1697
1740
1698
1741
for constant in api ["global_constants" ]:
1699
- header .append (f'\t const int { escape_identifier (constant ["name" ])} = { constant ["value" ]} ;' )
1742
+ header .append (f'\t const int64_t { escape_identifier (constant ["name" ])} = { constant ["value" ]} ;' )
1700
1743
1701
1744
header .append ("" )
1702
1745
@@ -2073,7 +2116,7 @@ def make_varargs_template(
2073
2116
if with_public_declare :
2074
2117
function_signature = "public: "
2075
2118
2076
- function_signature += "template<class ... Args> "
2119
+ function_signature += "template<typename ... Args> "
2077
2120
2078
2121
if static :
2079
2122
function_signature += "static "
0 commit comments