mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-01 01:08:01 +03:00

This is to be used when an error is discovered in a Lua Script. The var ScriptErrorMode refers to the error mode the user has chosen (silent, warn, terminate). At the moment this is hardcoded but will soon become editable to a LD via settings. ScriptAssert will read this variable and take the appropriate action when an assert is failed. IGNORE will do nothing (we should make a note in the documentation that this should almost certainly not be used by the LD if they can avoid it). WARN will call TENLog with LogLevel::Warn. TERMINATE will throw a TENScriptException, where it will be caught at GameMain, where TENLog will be called. There are circumstances where we will HAVE to terminate, even if the user has opted not to (i.e. errors where there is nothing sensible that can be done, such as syntax errors that would terminate Lua anyway). For these, we can pass in ERROR_MODE::TERMINATE as the last variable.
22 lines
470 B
C++
22 lines
470 B
C++
#include "framework.h"
|
|
#include "ScriptAssert.h"
|
|
|
|
ERROR_MODE ScriptErrorMode = ERROR_MODE::WARN;
|
|
|
|
bool ScriptAssert(bool cond, std::string const& msg, std::optional<ERROR_MODE> forceMode)
|
|
{
|
|
if (!cond)
|
|
{
|
|
ERROR_MODE mode = forceMode ? *forceMode : ScriptErrorMode;
|
|
switch (mode)
|
|
{
|
|
case ERROR_MODE::WARN:
|
|
TENLog(msg, LogLevel::Warning, LogConfig::All);
|
|
break;
|
|
case ERROR_MODE::TERMINATE:
|
|
throw TENScriptException(msg);
|
|
break;
|
|
}
|
|
}
|
|
return cond;
|
|
}
|