Changeset - r27363:4eb85dfe2aac
[Not reviewed]
master
0 4 0
Rubidium - 19 months ago 2023-05-05 17:32:27
rubidium@openttd.org
Codechange: use std::string for script log calls
4 files changed with 14 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_controller.cpp
Show inline comments
 
@@ -45,15 +45,13 @@
 
	throw Script_Suspend(ticks, nullptr);
 
}
 

	
 
/* static */ void ScriptController::Break(const char* message)
 
/* static */ void ScriptController::Break(const std::string &message)
 
{
 
	if (_network_dedicated || !_settings_client.gui.ai_developer_tools) return;
 

	
 
	ScriptObject::GetActiveInstance()->Pause();
 

	
 
	char log_message[1024];
 
	seprintf(log_message, lastof(log_message), "Break: %s", message);
 
	ScriptLog::Log(ScriptLogTypes::LOG_SQ_ERROR, log_message);
 
	ScriptLog::Log(ScriptLogTypes::LOG_SQ_ERROR, fmt::format("Break: {}", message));
 

	
 
	/* Inform script developer that their script has been paused and
 
	 * needs manual action to continue. */
 
@@ -64,7 +62,7 @@
 
	}
 
}
 

	
 
/* static */ void ScriptController::Print(bool error_msg, const char *message)
 
/* static */ void ScriptController::Print(bool error_msg, const std::string &message)
 
{
 
	ScriptLog::Log(error_msg ? ScriptLogTypes::LOG_SQ_ERROR : ScriptLogTypes::LOG_SQ_INFO, message);
 
}
src/script/api/script_controller.hpp
Show inline comments
 
@@ -181,7 +181,7 @@ public:
 
	 * @note gui.ai_developer_tools setting must be enabled or the break is
 
	 * ignored.
 
	 */
 
	static void Break(const char* message);
 
	static void Break(const std::string &message);
 

	
 
	/**
 
	 * When Squirrel triggers a print, this function is called.
 
@@ -190,7 +190,7 @@ public:
 
	 * @param message The message Squirrel logged.
 
	 * @note Use ScriptLog.Info/Warning/Error instead of 'print'.
 
	 */
 
	static void Print(bool error_msg, const char *message);
 
	static void Print(bool error_msg, const std::string &message);
 

	
 
	/**
 
	 * Import a library.
src/script/api/script_log.cpp
Show inline comments
 
@@ -17,22 +17,22 @@
 

	
 
#include "../../safeguards.h"
 

	
 
/* static */ void ScriptLog::Info(const char *message)
 
/* static */ void ScriptLog::Info(const std::string &message)
 
{
 
	ScriptLog::Log(ScriptLogTypes::LOG_INFO, message);
 
}
 

	
 
/* static */ void ScriptLog::Warning(const char *message)
 
/* static */ void ScriptLog::Warning(const std::string &message)
 
{
 
	ScriptLog::Log(ScriptLogTypes::LOG_WARNING, message);
 
}
 

	
 
/* static */ void ScriptLog::Error(const char *message)
 
/* static */ void ScriptLog::Error(const std::string &message)
 
{
 
	ScriptLog::Log(ScriptLogTypes::LOG_ERROR, message);
 
}
 

	
 
/* static */ void ScriptLog::Log(ScriptLogTypes::ScriptLogType level, const char *message)
 
/* static */ void ScriptLog::Log(ScriptLogTypes::ScriptLogType level, const std::string &message)
 
{
 
	ScriptLogTypes::LogData &logdata = ScriptObject::GetLogData();
 

	
 
@@ -43,8 +43,7 @@
 
	line.type = level;
 

	
 
	/* Cut string after first \n */
 
	const char *newline = strchr(message, '\n');
 
	line.text = std::string(message, 0, newline == nullptr ? strlen(message) : newline - message);
 
	line.text = message.substr(0, message.find_first_of('\n'));
 

	
 
	char logc;
 

	
src/script/api/script_log.hpp
Show inline comments
 
@@ -27,27 +27,27 @@ public:
 
	 * @param message The message to log.
 
	 * @note Special characters such as U+0000-U+0019 and U+E000-U+E1FF are not supported and removed or replaced by a question mark. This includes newlines and tabs.
 
	 */
 
	static void Info(const char *message);
 
	static void Info(const std::string &message);
 

	
 
	/**
 
	 * Print a Warning message to the logs.
 
	 * @param message The message to log.
 
	 * @note Special characters such as U+0000-U+0019 and U+E000-U+E1FF are not supported and removed or replaced by a question mark. This includes newlines and tabs.
 
	 */
 
	static void Warning(const char *message);
 
	static void Warning(const std::string &message);
 

	
 
	/**
 
	 * Print an Error message to the logs.
 
	 * @param message The message to log.
 
	 * @note Special characters such as U+0000-U+0019 and U+E000-U+E1FF are not supported and removed or replaced by a question mark. This includes newlines and tabs.
 
	 */
 
	static void Error(const char *message);
 
	static void Error(const std::string &message);
 

	
 
private:
 
	/**
 
	 * Internal command to log the message in a common way.
 
	 */
 
	static void Log(ScriptLogTypes::ScriptLogType level, const char *message);
 
	static void Log(ScriptLogTypes::ScriptLogType level, const std::string &message);
 
};
 

	
 
#endif /* SCRIPT_LOG_HPP */
0 comments (0 inline, 0 general)