mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-10 04:26:42 +03:00
Document errorMode. Make it an enum on the Lua side rather than a string.
This commit is contained in:
parent
85b26b4238
commit
e5d12a56f2
5 changed files with 38 additions and 23 deletions
|
@ -110,6 +110,7 @@ You will not need to call them manually.
|
|||
MakeReadOnlyTable("InvItem", kInventorySlots);
|
||||
MakeReadOnlyTable("RotationAxis", kRotAxes);
|
||||
MakeReadOnlyTable("ItemAction", kItemActions);
|
||||
MakeReadOnlyTable("ErrorMode", kErrorModes);
|
||||
}
|
||||
|
||||
GameFlow::~GameFlow()
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
#include "framework.h"
|
||||
#include "GameScriptSettings.h"
|
||||
|
||||
/***
|
||||
Settings that will be run on game startup.
|
||||
@classmod Settings
|
||||
@pragma nostrip
|
||||
*/
|
||||
|
||||
void GameScriptSettings::Register(sol::state* lua)
|
||||
{
|
||||
lua->new_usertype<GameScriptSettings>("Settings",
|
||||
|
@ -12,6 +18,24 @@ void GameScriptSettings::Register(sol::state* lua)
|
|||
"drawingDistance", &GameScriptSettings::DrawingDistance,
|
||||
"showRendererSteps", &GameScriptSettings::ShowRendererSteps,
|
||||
"showDebugInfo", &GameScriptSettings::ShowDebugInfo,
|
||||
|
||||
/*** How should the application respond to script errors?
|
||||
Must be one of the following:
|
||||
`ErrorMode.TERMINATE` - print to the log file and terminate the application when any script error is hit.
|
||||
This is the one you will want to go for if you want to know IMMEDIATELY if something has gone wrong.
|
||||
|
||||
`ErrorMode.WARN` - print to the log file and continue running the application when a recoverable script error is hit.
|
||||
Choose this one if terminating the application is too much for you. Note that unrecoverable errors will still terminate
|
||||
the application.
|
||||
|
||||
`ErrorMode.SILENT` - do nothing when a recoverable script error is hit.
|
||||
Think __very__ carefully before using this setting. These error modes are here to help you to keep your scripts
|
||||
working properly, but if you opt to ignore errors, you won't be alerted if you've misused a function or passed
|
||||
an invalid argument.
|
||||
|
||||
As with `ErrorMode.WARN`, unrecoverable errors will still terminate the application.
|
||||
@mem errorMode
|
||||
*/
|
||||
"errorMode", &GameScriptSettings::ErrorMode
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "GameScriptSettings.h"
|
||||
#include "ScriptAssert.h"
|
||||
#include <string>
|
||||
|
||||
static const std::unordered_map<std::string, ERROR_MODE> kErrorModes {
|
||||
{"SILENT", ERROR_MODE::SILENT},
|
||||
{"WARN", ERROR_MODE::WARN},
|
||||
{"TERMINATE", ERROR_MODE::TERMINATE}
|
||||
};
|
||||
|
||||
namespace sol {
|
||||
class state;
|
||||
}
|
||||
|
@ -18,7 +24,7 @@ struct GameScriptSettings
|
|||
int DrawingDistance;
|
||||
bool ShowRendererSteps;
|
||||
bool ShowDebugInfo;
|
||||
std::string ErrorMode;
|
||||
ERROR_MODE ErrorMode;
|
||||
|
||||
static void Register(sol::state* lua);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -13,4 +13,4 @@ void ScriptWarn(std::string const& msg);
|
|||
|
||||
bool ScriptAssert(bool cond, std::string const& msg, std::optional<ERROR_MODE> forceMode = std::nullopt);
|
||||
|
||||
void SetErrorMode(std::string const& mode);
|
||||
void SetErrorMode(ERROR_MODE mode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue