You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
C# bindings generator cleanup
- Normal log messages are no longer warnings. - BindingsGenerator is no longer a singleton. - Added a log function.
This commit is contained in:
@@ -32,6 +32,8 @@
|
||||
|
||||
#include "core/os/file_access.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace {
|
||||
|
||||
int sfind(const String &p_text, int p_from) {
|
||||
@@ -184,3 +186,50 @@ Error read_all_file_utf8(const String &p_path, String &r_content) {
|
||||
r_content = source;
|
||||
return OK;
|
||||
}
|
||||
|
||||
// TODO: Move to variadic templates once we upgrade to C++11
|
||||
|
||||
String str_format(const char *p_format, ...) {
|
||||
va_list list;
|
||||
|
||||
va_start(list, p_format);
|
||||
String res = str_format(p_format, list);
|
||||
va_end(list);
|
||||
|
||||
return res;
|
||||
}
|
||||
// va_copy was defined in the C99, but not in C++ standards before C++11.
|
||||
// When you compile C++ without --std=c++<XX> option, compilers still define
|
||||
// va_copy, otherwise you have to use the internal version (__va_copy).
|
||||
#if !defined(va_copy)
|
||||
#if defined(__GNUC__)
|
||||
#define va_copy(d, s) __va_copy((d), (s))
|
||||
#else
|
||||
#define va_copy(d, s) ((d) = (s))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MINGW_ENABLED) || defined(_MSC_VER)
|
||||
#define vsnprintf vsnprintf_s
|
||||
#endif
|
||||
|
||||
String str_format(const char *p_format, va_list p_list) {
|
||||
va_list list;
|
||||
|
||||
va_copy(list, p_list);
|
||||
int len = vsnprintf(NULL, 0, p_format, list);
|
||||
va_end(list);
|
||||
|
||||
len += 1; // for the trailing '/0'
|
||||
|
||||
char *buffer(memnew_arr(char, len));
|
||||
|
||||
va_copy(list, p_list);
|
||||
vsnprintf(buffer, len, p_format, list);
|
||||
va_end(list);
|
||||
|
||||
String res(buffer);
|
||||
memdelete_arr(buffer);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user