From 01db553c49345b683ff9da3283bc92a8c2933af2 Mon Sep 17 00:00:00 2001 From: danielytics Date: Wed, 7 Mar 2018 10:27:34 +0000 Subject: [PATCH] adds Array::make and Dictionary::make static methods and has variadic template functions use those --- binding_generator.py | 2 +- include/core/Array.hpp | 6 ++++++ include/core/Dictionary.hpp | 5 +++++ include/core/Godot.hpp | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index a7d874df..c39e7edd 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -221,7 +221,7 @@ def generate_class_header(used_classes, c): if len(method["arguments"]) > 0: method_signature += ", " method_arguments += ", " - vararg_templates += "\ttemplate " + method_signature + "Args... args){\n\t\treturn " + method_name + "(" + method_arguments + "godot::helpers::append_all(Array(), args...));\n\t}\n""" + vararg_templates += "\ttemplate " + 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" if method["is_const"] and not c["singleton"] else "") diff --git a/include/core/Array.hpp b/include/core/Array.hpp index 23205686..ead3ba3b 100644 --- a/include/core/Array.hpp +++ b/include/core/Array.hpp @@ -3,6 +3,7 @@ #include +#include "Defs.hpp" #include "String.hpp" namespace godot { @@ -39,6 +40,11 @@ public: Array(const PoolColorArray& a); + template + static Array make(Args... args) { + return helpers::append_all(Array(), args...); + } + Variant& operator [](const int idx); Variant operator [](const int idx) const; diff --git a/include/core/Dictionary.hpp b/include/core/Dictionary.hpp index ec496af6..613d6ce3 100644 --- a/include/core/Dictionary.hpp +++ b/include/core/Dictionary.hpp @@ -16,6 +16,11 @@ public: Dictionary(const Dictionary & other); Dictionary & operator=(const Dictionary & other); + template + static Dictionary make(Args... args) { + return helpers::add_all(Dictionary(), args...); + } + void clear(); bool empty() const; diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index 8c463b69..01bee09f 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -487,7 +487,7 @@ void register_signal(String name, Dictionary args = Dictionary()) template void register_signal(String name, Args... varargs) { - register_signal(name, helpers::add_all(Dictionary(), varargs...)); + register_signal(name, Dictionary::make(varargs...)); } }