Codechange: introduce and use std::string variant of sq_throwerror

This commit is contained in:
Rubidium
2023-05-06 00:04:10 +02:00
committed by rubidium42
parent 3453c03a17
commit e035705239
6 changed files with 18 additions and 32 deletions

View File

@@ -14,6 +14,7 @@
#include "script_info.hpp"
#include "script_scanner.hpp"
#include "../3rdparty/fmt/format.h"
#include "../safeguards.h"
@@ -32,9 +33,7 @@ ScriptInfo::~ScriptInfo()
bool ScriptInfo::CheckMethod(const char *name) const
{
if (!this->engine->MethodExists(*this->SQ_instance, name)) {
char error[1024];
seprintf(error, lastof(error), "your info.nut/library.nut doesn't have the method '%s'", name);
this->engine->ThrowError(error);
this->engine->ThrowError(fmt::format("your info.nut/library.nut doesn't have the method '{}'", name));
return false;
}
return true;
@@ -168,9 +167,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
config.flags = (ScriptConfigFlags)res;
items |= 0x100;
} else {
char error[1024];
seprintf(error, lastof(error), "unknown setting property '%s'", key);
this->engine->ThrowError(error);
this->engine->ThrowError(fmt::format("unknown setting property '{}'", key));
return SQ_ERROR;
}
@@ -181,9 +178,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
/* Don't allow both random_deviation and SCRIPTCONFIG_RANDOM to
* be set for the same config item. */
if ((items & 0x200) != 0 && (config.flags & SCRIPTCONFIG_RANDOM) != 0) {
char error[1024];
seprintf(error, lastof(error), "Setting both random_deviation and SCRIPTCONFIG_RANDOM is not allowed");
this->engine->ThrowError(error);
this->engine->ThrowError("Setting both random_deviation and SCRIPTCONFIG_RANDOM is not allowed");
return SQ_ERROR;
}
/* Reset the bit for random_deviation as it's optional. */
@@ -192,9 +187,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
/* Make sure all properties are defined */
uint mask = (config.flags & SCRIPTCONFIG_BOOLEAN) ? 0x1F3 : 0x1FF;
if (items != mask) {
char error[1024];
seprintf(error, lastof(error), "please define all properties of a setting (min/max not allowed for booleans)");
this->engine->ThrowError(error);
this->engine->ThrowError("please define all properties of a setting (min/max not allowed for booleans)");
return SQ_ERROR;
}
@@ -214,9 +207,7 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
}
if (config == nullptr) {
char error[1024];
seprintf(error, lastof(error), "Trying to add labels for non-defined setting '%s'", setting_name);
this->engine->ThrowError(error);
this->engine->ThrowError(fmt::format("Trying to add labels for non-defined setting '{}'", setting_name));
return SQ_ERROR;
}
if (!config->labels.empty()) return SQ_ERROR;