mirror of https://github.com/OpenTTD/OpenTTD.git
Change: [Script] Let Script_FatalError use std::string instead of const char *
This commit is contained in:
parent
c9c208f78e
commit
7aaaa2c5f5
|
@ -19,7 +19,7 @@ public:
|
||||||
* Creates a "fatal error" exception.
|
* Creates a "fatal error" exception.
|
||||||
* @param msg The message describing the cause of the fatal error.
|
* @param msg The message describing the cause of the fatal error.
|
||||||
*/
|
*/
|
||||||
Script_FatalError(const char *msg) :
|
Script_FatalError(const std::string &msg) :
|
||||||
msg(msg)
|
msg(msg)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@ public:
|
||||||
* The error message associated with the fatal error.
|
* The error message associated with the fatal error.
|
||||||
* @return The error message.
|
* @return The error message.
|
||||||
*/
|
*/
|
||||||
const char *GetErrorMessage() { return msg; }
|
const std::string &GetErrorMessage() const { return msg; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *msg; ///< The error message.
|
const std::string msg; ///< The error message.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SCRIPT_FATALERROR_HPP */
|
#endif /* SCRIPT_FATALERROR_HPP */
|
||||||
|
|
|
@ -100,7 +100,7 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na
|
||||||
ScriptObject::SetAllowDoCommand(true);
|
ScriptObject::SetAllowDoCommand(true);
|
||||||
} catch (Script_FatalError &e) {
|
} catch (Script_FatalError &e) {
|
||||||
this->is_dead = true;
|
this->is_dead = true;
|
||||||
this->engine->ThrowError(e.GetErrorMessage());
|
this->engine->ThrowError(e.GetErrorMessage().c_str());
|
||||||
this->engine->ResumeError();
|
this->engine->ResumeError();
|
||||||
this->Died();
|
this->Died();
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ void ScriptInstance::GameLoop()
|
||||||
this->callback = e.GetSuspendCallback();
|
this->callback = e.GetSuspendCallback();
|
||||||
} catch (Script_FatalError &e) {
|
} catch (Script_FatalError &e) {
|
||||||
this->is_dead = true;
|
this->is_dead = true;
|
||||||
this->engine->ThrowError(e.GetErrorMessage());
|
this->engine->ThrowError(e.GetErrorMessage().c_str());
|
||||||
this->engine->ResumeError();
|
this->engine->ResumeError();
|
||||||
this->Died();
|
this->Died();
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ void ScriptInstance::GameLoop()
|
||||||
this->callback = e.GetSuspendCallback();
|
this->callback = e.GetSuspendCallback();
|
||||||
} catch (Script_FatalError &e) {
|
} catch (Script_FatalError &e) {
|
||||||
this->is_dead = true;
|
this->is_dead = true;
|
||||||
this->engine->ThrowError(e.GetErrorMessage());
|
this->engine->ThrowError(e.GetErrorMessage().c_str());
|
||||||
this->engine->ResumeError();
|
this->engine->ResumeError();
|
||||||
this->Died();
|
this->Died();
|
||||||
}
|
}
|
||||||
|
@ -505,7 +505,7 @@ void ScriptInstance::Save()
|
||||||
/* If we don't mark the script as dead here cleaning up the squirrel
|
/* If we don't mark the script as dead here cleaning up the squirrel
|
||||||
* stack could throw Script_FatalError again. */
|
* stack could throw Script_FatalError again. */
|
||||||
this->is_dead = true;
|
this->is_dead = true;
|
||||||
this->engine->ThrowError(e.GetErrorMessage());
|
this->engine->ThrowError(e.GetErrorMessage().c_str());
|
||||||
this->engine->ResumeError();
|
this->engine->ResumeError();
|
||||||
SaveEmpty();
|
SaveEmpty();
|
||||||
/* We can't kill the script here, so mark it as crashed (not dead) and
|
/* We can't kill the script here, so mark it as crashed (not dead) and
|
||||||
|
|
|
@ -38,7 +38,7 @@ bool ScriptScanner::AddFile(const std::string &filename, size_t basepath_length,
|
||||||
try {
|
try {
|
||||||
this->engine->LoadScript(filename.c_str());
|
this->engine->LoadScript(filename.c_str());
|
||||||
} catch (Script_FatalError &e) {
|
} 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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue