summaryrefslogtreecommitdiff
path: root/core/variant/variant.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/variant/variant.h')
-rw-r--r--core/variant/variant.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 212f94a9a8..9b213a7682 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -807,7 +807,22 @@ const Variant::ObjData &Variant::_get_obj() const {
return *reinterpret_cast<const ObjData *>(&_data._mem[0]);
}
-String vformat(const String &p_text, const Variant &p1 = Variant(), const Variant &p2 = Variant(), const Variant &p3 = Variant(), const Variant &p4 = Variant(), const Variant &p5 = Variant());
+template <typename... VarArgs>
+String vformat(const String &p_text, const VarArgs... p_args) {
+ Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
+ Array args_array;
+ args_array.resize(sizeof...(p_args));
+ for (uint32_t i = 0; i < sizeof...(p_args); i++) {
+ args_array[i] = args[i];
+ }
+
+ bool error = false;
+ String fmt = p_text.sprintf(args_array, &error);
+
+ ERR_FAIL_COND_V_MSG(error, String(), fmt);
+
+ return fmt;
+}
template <typename... VarArgs>
Callable Callable::bind(VarArgs... p_args) {