Document errorMode. Make it an enum on the Lua side rather than a string.

This commit is contained in:
hispidence 2021-08-16 12:52:06 +01:00
parent 1ad81f4a63
commit af84f318b6
5 changed files with 38 additions and 23 deletions

View file

@ -23,9 +23,10 @@ bool ScriptAssert(bool cond, std::string const& msg, std::optional<ERROR_MODE> f
switch (mode)
{
case ERROR_MODE::WARN:
TENLog(msg, LogLevel::Warning, LogConfig::All);
TENLog(msg, LogLevel::Error, LogConfig::All);
break;
case ERROR_MODE::TERMINATE:
TENLog(msg, LogLevel::Error, LogConfig::All);
throw TENScriptException(msg);
break;
}
@ -33,24 +34,7 @@ bool ScriptAssert(bool cond, std::string const& msg, std::optional<ERROR_MODE> f
return cond;
}
void SetErrorMode(std::string const& mode)
void SetErrorMode(ERROR_MODE mode)
{
std::string noCase{ mode };
std::transform(std::cbegin(noCase), std::cend(noCase), std::begin(noCase), [](unsigned char c) {return std::tolower(c); });
if (noCase == "silent")
{
ScriptErrorMode = ERROR_MODE::SILENT;
}
else if (noCase == "warn")
{
ScriptErrorMode = ERROR_MODE::WARN;
}
else if (noCase == "terminate")
{
ScriptErrorMode = ERROR_MODE::TERMINATE;
}
else
{
TENLog("Wrong error mode set - valid settings are \"silent\", \"warn\" and \"terminate\"; defaulting to \"warn\".", LogLevel::Warning);
}
ScriptErrorMode = mode;
}