From 2343a8a54c13c2ccc617ed6716419dd568bb997f Mon Sep 17 00:00:00 2001 From: karroffel Date: Fri, 2 Mar 2018 19:04:57 +0100 Subject: fix #101 --- include/core/NodePath.hpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/core') diff --git a/include/core/NodePath.hpp b/include/core/NodePath.hpp index 026414b..e9e60ac 100644 --- a/include/core/NodePath.hpp +++ b/include/core/NodePath.hpp @@ -36,6 +36,8 @@ public: void operator =(const NodePath& other); + bool operator ==(const NodePath& other); + ~NodePath(); }; -- cgit v1.2.3 From c7b03c4132f9be5846141fb101f8f89522eb8efa Mon Sep 17 00:00:00 2001 From: danielytics Date: Tue, 6 Mar 2018 10:26:07 +0000 Subject: make register_signal and auto-generated variadic funcitons use variadic templates to streamline their use --- include/core/Defs.hpp | 36 ++++++++++++++++++++++++++++++++++++ include/core/Godot.hpp | 5 +++++ 2 files changed, 41 insertions(+) (limited to 'include/core') diff --git a/include/core/Defs.hpp b/include/core/Defs.hpp index f8c76d3..0306219 100644 --- a/include/core/Defs.hpp +++ b/include/core/Defs.hpp @@ -58,6 +58,42 @@ enum Error { ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above }; + namespace helpers { + template + T append_all (T appendable, ValueT value) { + appendable.append(value); + return appendable; + } + + template + T append_all (T appendable, ValueT value, Args... args) { + appendable.append(value); + return append_all(appendable, args...); + } + + template + T append_all (T appendable) { + return appendable; + } + + template + KV add_all (KV kv, KeyT key, ValueT value) { + kv[key] = value; + return kv; + } + + template + KV add_all (KV kv, KeyT key, ValueT value, Args... args) { + kv[key] = value; + return add_all(kv, args...); + } + + template + KV add_all (KV kv) { + return kv; + } + } + } #include diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index 6d0289f..8c463b6 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -484,6 +484,11 @@ void register_signal(String name, Dictionary args = Dictionary()) } } +template +void register_signal(String name, Args... varargs) +{ + register_signal(name, helpers::add_all(Dictionary(), varargs...)); +} } -- cgit v1.2.3 From 01db553c49345b683ff9da3283bc92a8c2933af2 Mon Sep 17 00:00:00 2001 From: danielytics Date: Wed, 7 Mar 2018 10:27:34 +0000 Subject: adds Array::make and Dictionary::make static methods and has variadic template functions use those --- include/core/Array.hpp | 6 ++++++ include/core/Dictionary.hpp | 5 +++++ include/core/Godot.hpp | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'include/core') diff --git a/include/core/Array.hpp b/include/core/Array.hpp index 2320568..ead3ba3 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 ec496af..613d6ce 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 8c463b6..01bee09 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...)); } } -- cgit v1.2.3 From e74b8f593ecd412ee410f538ac88aa8b91d24b33 Mon Sep 17 00:00:00 2001 From: danielytics Date: Wed, 7 Mar 2018 12:21:33 +0000 Subject: adds variadic printing function, makes String.format custom placeholder work --- include/core/GodotGlobal.hpp | 6 ++++++ include/core/String.hpp | 2 ++ 2 files changed, 8 insertions(+) (limited to 'include/core') diff --git a/include/core/GodotGlobal.hpp b/include/core/GodotGlobal.hpp index 7d28dba..a913359 100644 --- a/include/core/GodotGlobal.hpp +++ b/include/core/GodotGlobal.hpp @@ -3,6 +3,7 @@ #include #include "String.hpp" +#include "Array.hpp" namespace godot { @@ -20,6 +21,11 @@ public: static void gdnative_init(godot_gdnative_init_options *o); static void gdnative_terminate(godot_gdnative_terminate_options *o); static void nativescript_init(void *handle); + + template + static void print(const String& fmt, Args... values) { + print(fmt.format(Array::make(values...))); + } }; diff --git a/include/core/String.hpp b/include/core/String.hpp index de65f3c..7826fcb 100644 --- a/include/core/String.hpp +++ b/include/core/String.hpp @@ -81,6 +81,7 @@ public: int find(String what, int from = 0) const; int find_last(String what) const; int findn(String what, int from = 0) const; + String format(Variant values) const; String format(Variant values, String placeholder) const; String get_base_dir() const; String get_basename() const; @@ -128,6 +129,7 @@ public: String to_upper() const; String xml_escape() const; String xml_unescape() const; + }; String operator+(const char *a, const String &b); -- cgit v1.2.3 From a6689b21322e976488aa7482aafb748b47ca8158 Mon Sep 17 00:00:00 2001 From: Gary Oberbrunner Date: Tue, 13 Mar 2018 10:07:50 -0400 Subject: Make all Pool*Array::operator[] as const This is needed since that operator returns a local copy, not an lvalue. Attempting to write to the return value of these operators wouldn't change the array element. PoolVectors need locking when writing, so this operator can't return a writable reference. To update a Pool*Array, use the `set()` method which locks and unlocks the array. For multiple writes, use the `write()` method which returns a locked writable view, and unlocks when it goes out of scope. --- include/core/PoolArrays.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include/core') diff --git a/include/core/PoolArrays.hpp b/include/core/PoolArrays.hpp index 78a370d..fadcfad 100644 --- a/include/core/PoolArrays.hpp +++ b/include/core/PoolArrays.hpp @@ -104,7 +104,7 @@ public: void set(const int idx, const uint8_t data); - uint8_t operator [](const int idx); + const uint8_t operator [](const int idx); int size() const; @@ -200,7 +200,7 @@ public: void set(const int idx, const int data); - int operator [](const int idx); + const int operator [](const int idx); int size() const; @@ -296,7 +296,7 @@ public: void set(const int idx, const real_t data); - real_t operator [](const int idx); + const real_t operator [](const int idx); int size() const; @@ -392,7 +392,7 @@ public: void set(const int idx, const String& data); - String operator [](const int idx); + const String operator [](const int idx); int size() const; @@ -489,7 +489,7 @@ public: void set(const int idx, const Vector2& data); - Vector2 operator [](const int idx); + const Vector2 operator [](const int idx); int size() const; @@ -585,7 +585,7 @@ public: void set(const int idx, const Vector3& data); - Vector3 operator [](const int idx); + const Vector3 operator [](const int idx); int size() const; @@ -681,7 +681,7 @@ public: void set(const int idx, const Color& data); - Color operator [](const int idx); + const Color operator [](const int idx); int size() const; -- cgit v1.2.3