Replace WarningsAsErrors usage with ScriptAssert usage.

For recoverable errors, add some recovery behaviour and logging so a level designer can see in the log what was done as a result of the error.

Warn about default behaviour if no callbacks are added.
This commit is contained in:
hispidence 2021-08-04 16:51:28 +01:00
parent 052b03ec96
commit ead31e63f2
9 changed files with 36 additions and 61 deletions

View file

@ -1,16 +1,13 @@
#pragma once
#include "ScriptAssert.h"
#include <functional>
#include <string>
extern bool const WarningsAsErrors;
#define index_error_maker(CPP_TYPE, LUA_CLASS_NAME) [](CPP_TYPE & item, sol::object key) \
{ \
if (WarningsAsErrors) \
{ \
std::string err = "Attempted to read non-existant var \"" + key.as<std::string>() + "\" from " + LUA_CLASS_NAME; \
throw std::runtime_error(err); \
} \
std::string err = "Attempted to read non-existant var \"" + key.as<std::string>() + "\" from " + LUA_CLASS_NAME; \
throw TENScriptException(err); \
}
template <typename S> using callbackSetName = std::function<bool(std::string const&, S identifier)>;
@ -37,20 +34,13 @@ protected:
// default callbacks
template <typename T, typename S> callbackSetName<S> GameScriptNamedBase<T, S>::s_callbackSetName = [](std::string const& n, S identifier) {
std::string err = "\"Set Name\" callback is not set.";
if (WarningsAsErrors)
{
throw TENScriptException(err);
}
throw TENScriptException(err);
return false;
};
template <typename T, typename S> callbackRemoveName GameScriptNamedBase<T, S>::s_callbackRemoveName = [](std::string const& n) {
std::string err = "\"Remove Name\" callback is not set.";
if (WarningsAsErrors)
{
throw TENScriptException(err);
}
throw TENScriptException(err);
return false;
};