This commit is contained in:
Nickolai Korshunov
2018-04-25 11:40:49 +03:00
15 changed files with 259 additions and 90 deletions

View File

@@ -3,6 +3,7 @@
#include <gdnative/array.h>
#include "Defs.hpp"
#include "String.hpp"
namespace godot {
@@ -39,6 +40,11 @@ public:
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) const;

View File

@@ -58,6 +58,42 @@ enum class Error {
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
};
namespace helpers {
template <typename T, typename ValueT>
T append_all (T appendable, ValueT value) {
appendable.append(value);
return appendable;
}
template <typename T, typename ValueT, typename... Args>
T append_all (T appendable, ValueT value, Args... args) {
appendable.append(value);
return append_all(appendable, args...);
}
template <typename T>
T append_all (T appendable) {
return appendable;
}
template <typename KV, typename KeyT, typename ValueT>
KV add_all (KV kv, KeyT key, ValueT value) {
kv[key] = value;
return kv;
}
template <typename KV, typename KeyT, typename ValueT, typename... Args>
KV add_all (KV kv, KeyT key, ValueT value, Args... args) {
kv[key] = value;
return add_all(kv, args...);
}
template <typename KV>
KV add_all (KV kv) {
return kv;
}
}
}
#include <stdio.h>

View File

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

View File

@@ -484,6 +484,11 @@ void register_signal(String name, Dictionary args = Dictionary())
}
}
template<class T, class... Args>
void register_signal(String name, Args... varargs)
{
register_signal<T>(name, Dictionary::make(varargs...));
}
}

View File

@@ -3,6 +3,7 @@
#include <gdnative_api_struct.gen.h>
#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 <class... Args>
static void print(const String& fmt, Args... values) {
print(fmt.format(Array::make(values...)));
}
};

View File

@@ -36,6 +36,8 @@ public:
void operator =(const NodePath& other);
bool operator ==(const NodePath& other);
~NodePath();
};

View File

@@ -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;

View File

@@ -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);