瀏覽代碼

adds Array::make and Dictionary::make static methods and has variadic template functions use those

danielytics 7 年之前
父節點
當前提交
01db553c49
共有 4 個文件被更改,包括 13 次插入2 次删除
  1. 1 1
      binding_generator.py
  2. 6 0
      include/core/Array.hpp
  3. 5 0
      include/core/Dictionary.hpp
  4. 1 1
      include/core/Godot.hpp

+ 1 - 1
binding_generator.py

@@ -221,7 +221,7 @@ def generate_class_header(used_classes, c):
             if len(method["arguments"]) > 0:
             if len(method["arguments"]) > 0:
                 method_signature += ", "
                 method_signature += ", "
                 method_arguments += ", "
                 method_arguments += ", "
-            vararg_templates += "\ttemplate <class... Args> " + method_signature + "Args... args){\n\t\treturn " + method_name + "(" + method_arguments + "godot::helpers::append_all(Array(), args...));\n\t}\n"""
+            vararg_templates += "\ttemplate <class... Args> " + method_signature + "Args... args){\n\t\treturn " + method_name + "(" + method_arguments + "Array::make(args...));\n\t}\n"""
             method_signature += "const Array& __var_args = Array()"
             method_signature += "const Array& __var_args = Array()"
             
             
         method_signature += ")" + (" const" if method["is_const"] and not c["singleton"] else "")
         method_signature += ")" + (" const" if method["is_const"] and not c["singleton"] else "")

+ 6 - 0
include/core/Array.hpp

@@ -3,6 +3,7 @@
 
 
 #include <gdnative/array.h>
 #include <gdnative/array.h>
 
 
+#include "Defs.hpp"
 #include "String.hpp"
 #include "String.hpp"
 
 
 namespace godot {
 namespace godot {
@@ -39,6 +40,11 @@ public:
 
 
 	Array(const PoolColorArray& a);
 	Array(const PoolColorArray& a);
 
 
+	template <class... Args>
+	static Array make(Args... args) {
+		return helpers::append_all(Array(), args...);
+	}
+
 	Variant& operator [](const int idx);
 	Variant& operator [](const int idx);
 
 
 	Variant operator [](const int idx) const;
 	Variant operator [](const int idx) const;

+ 5 - 0
include/core/Dictionary.hpp

@@ -16,6 +16,11 @@ public:
 	Dictionary(const Dictionary & other);
 	Dictionary(const Dictionary & other);
 	Dictionary & operator=(const Dictionary & other);
 	Dictionary & operator=(const Dictionary & other);
 
 
+	template <class... Args>
+	static Dictionary make(Args... args) {
+		return helpers::add_all(Dictionary(), args...);
+	}
+
 	void clear();
 	void clear();
 
 
 	bool empty() const;
 	bool empty() const;

+ 1 - 1
include/core/Godot.hpp

@@ -487,7 +487,7 @@ void register_signal(String name, Dictionary args = Dictionary())
 template<class T, class... Args>
 template<class T, class... Args>
 void register_signal(String name, Args... varargs)
 void register_signal(String name, Args... varargs)
 {
 {
-	register_signal<T>(name, helpers::add_all(Dictionary(), varargs...));
+	register_signal<T>(name, Dictionary::make(varargs...));
 }
 }
 
 
 }
 }