From 4400bbfa964dd6353f0cf7591f6be6a789039399 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 17 Apr 2021 09:59:18 +0200 Subject: [PATCH] Change: [Script] Let Script_FatalError use std::string instead of const char * --- src/script/script_fatalerror.hpp | 6 +++--- src/script/script_instance.cpp | 8 ++++---- src/script/script_scanner.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/script/script_fatalerror.hpp b/src/script/script_fatalerror.hpp index 5d1a2c1250..96c64e0b9d 100644 --- a/src/script/script_fatalerror.hpp +++ b/src/script/script_fatalerror.hpp @@ -19,7 +19,7 @@ public: * Creates a "fatal error" exception. * @param msg The message describing the cause of the fatal error. */ - Script_FatalError(const char *msg) : + Script_FatalError(const std::string &msg) : msg(msg) {} @@ -27,10 +27,10 @@ public: * The error message associated with the fatal error. * @return The error message. */ - const char *GetErrorMessage() { return msg; } + const std::string &GetErrorMessage() const { return msg; } private: - const char *msg; ///< The error message. + const std::string msg; ///< The error message. }; #endif /* SCRIPT_FATALERROR_HPP */ diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 8227060d35..f7f9de4fc8 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -100,7 +100,7 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na ScriptObject::SetAllowDoCommand(true); } catch (Script_FatalError &e) { this->is_dead = true; - this->engine->ThrowError(e.GetErrorMessage()); + this->engine->ThrowError(e.GetErrorMessage().c_str()); this->engine->ResumeError(); this->Died(); } @@ -228,7 +228,7 @@ void ScriptInstance::GameLoop() this->callback = e.GetSuspendCallback(); } catch (Script_FatalError &e) { this->is_dead = true; - this->engine->ThrowError(e.GetErrorMessage()); + this->engine->ThrowError(e.GetErrorMessage().c_str()); this->engine->ResumeError(); this->Died(); } @@ -249,7 +249,7 @@ void ScriptInstance::GameLoop() this->callback = e.GetSuspendCallback(); } catch (Script_FatalError &e) { this->is_dead = true; - this->engine->ThrowError(e.GetErrorMessage()); + this->engine->ThrowError(e.GetErrorMessage().c_str()); this->engine->ResumeError(); this->Died(); } @@ -505,7 +505,7 @@ void ScriptInstance::Save() /* If we don't mark the script as dead here cleaning up the squirrel * stack could throw Script_FatalError again. */ this->is_dead = true; - this->engine->ThrowError(e.GetErrorMessage()); + this->engine->ThrowError(e.GetErrorMessage().c_str()); this->engine->ResumeError(); SaveEmpty(); /* We can't kill the script here, so mark it as crashed (not dead) and diff --git a/src/script/script_scanner.cpp b/src/script/script_scanner.cpp index 6fa88bfee5..8b48809bf7 100644 --- a/src/script/script_scanner.cpp +++ b/src/script/script_scanner.cpp @@ -38,7 +38,7 @@ bool ScriptScanner::AddFile(const std::string &filename, size_t basepath_length, try { this->engine->LoadScript(filename.c_str()); } catch (Script_FatalError &e) { - DEBUG(script, 0, "Fatal error '%s' when trying to load the script '%s'.", e.GetErrorMessage(), filename.c_str()); + DEBUG(script, 0, "Fatal error '%s' when trying to load the script '%s'.", e.GetErrorMessage().c_str(), filename.c_str()); return false; } return true;