Skip to content

Commit 5255034

Browse files
authored
Merge pull request godotengine#1653 from aaronfranke/print
Add `print_line` for compatibility with engine modules
2 parents b378d8c + ac466e4 commit 5255034

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

include/godot_cpp/core/class_db.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <godot_cpp/core/error_macros.hpp>
3838
#include <godot_cpp/core/method_bind.hpp>
3939
#include <godot_cpp/core/object.hpp>
40+
#include <godot_cpp/core/print_string.hpp>
4041

4142
#include <godot_cpp/classes/class_db_singleton.hpp>
4243

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**************************************************************************/
2+
/* print_string.hpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#ifndef GODOT_PRINT_STRING_HPP
32+
#define GODOT_PRINT_STRING_HPP
33+
34+
#include <godot_cpp/variant/utility_functions.hpp>
35+
36+
namespace godot {
37+
inline void print_error(const Variant &p_variant) {
38+
UtilityFunctions::printerr(p_variant);
39+
}
40+
41+
inline void print_line(const Variant &p_variant) {
42+
UtilityFunctions::print(p_variant);
43+
}
44+
45+
inline void print_line_rich(const Variant &p_variant) {
46+
UtilityFunctions::print_rich(p_variant);
47+
}
48+
49+
template <typename... Args>
50+
void print_error(const Variant &p_variant, Args... p_args) {
51+
UtilityFunctions::printerr(p_variant, p_args...);
52+
}
53+
54+
template <typename... Args>
55+
void print_line(const Variant &p_variant, Args... p_args) {
56+
UtilityFunctions::print(p_variant, p_args...);
57+
}
58+
59+
template <typename... Args>
60+
void print_line_rich(const Variant &p_variant, Args... p_args) {
61+
UtilityFunctions::print_rich(p_variant, p_args...);
62+
}
63+
64+
bool is_print_verbose_enabled();
65+
66+
// Checking the condition before evaluating the text to be printed avoids processing unless it actually has to be printed, saving some CPU usage.
67+
#define print_verbose(m_variant) \
68+
{ \
69+
if (is_print_verbose_enabled()) { \
70+
print_line(m_variant); \
71+
} \
72+
}
73+
} // namespace godot
74+
75+
#endif // GODOT_PRINT_STRING_HPP

src/core/print_string.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**************************************************************************/
2+
/* print_string.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include <godot_cpp/core/print_string.hpp>
32+
33+
#include <godot_cpp/classes/os.hpp>
34+
35+
namespace godot {
36+
bool is_print_verbose_enabled() {
37+
return OS::get_singleton()->is_stdout_verbose();
38+
}
39+
} // namespace godot

0 commit comments

Comments
 (0)