/**************************************************************************/1/* print_string.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/variant/variant.h"3334extern void (*_print_func)(String);3536typedef void (*PrintHandlerFunc)(void *, const String &p_string, bool p_error, bool p_rich);3738struct PrintHandlerList {39PrintHandlerFunc printfunc = nullptr;40void *userdata = nullptr;4142PrintHandlerList *next = nullptr;4344PrintHandlerList() {}45};4647String stringify_variants(const Variant &p_var);4849template <typename... Args>50String stringify_variants(const Variant &p_var, Args... p_args) {51return p_var.operator String() + " " + stringify_variants(p_args...);52}5354void add_print_handler(PrintHandlerList *p_handler);55void remove_print_handler(const PrintHandlerList *p_handler);5657extern void __print_line(const String &p_string);58extern void __print_line_rich(const String &p_string);59extern void print_raw(const String &p_string);60extern void print_error(const String &p_string);61extern bool is_print_verbose_enabled();6263// This version avoids processing the text to be printed until it actually has to be printed, saving some CPU usage.64#define print_verbose(m_text) \65{ \66if (is_print_verbose_enabled()) { \67print_line(m_text); \68} \69}7071inline void print_line(const Variant &v) {72__print_line(stringify_variants(v));73}7475inline void print_line_rich(const Variant &v) {76__print_line_rich(stringify_variants(v));77}7879template <typename... Args>80void print_line(const Variant &p_var, Args... p_args) {81__print_line(stringify_variants(p_var, p_args...));82}8384template <typename... Args>85void print_line_rich(const Variant &p_var, Args... p_args) {86__print_line_rich(stringify_variants(p_var, p_args...));87}888990