summaryrefslogtreecommitdiff
path: root/src/script/api/script_error.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/api/script_error.hpp')
-rw-r--r--src/script/api/script_error.hpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/script/api/script_error.hpp b/src/script/api/script_error.hpp
index 33a69e544..1817cdb7d 100644
--- a/src/script/api/script_error.hpp
+++ b/src/script/api/script_error.hpp
@@ -39,6 +39,21 @@
}
/**
+ * Helper to write precondition enforcers for the script API in an abbreviated manner for encoded texts.
+ * @param returnval The value to return on failure.
+ * @param string The string that is checked.
+ */
+#define EnforcePreconditionEncodedText(returnval, string) \
+ if ((string) == NULL) { \
+ ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_TOO_MANY_PARAMETERS); \
+ return returnval; \
+ } \
+ if (StrEmpty(string)) { \
+ ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_FAILED); \
+ return returnval; \
+ }
+
+/**
* Class that handles all error related functions.
* @api ai game
*/
@@ -81,6 +96,8 @@ public:
ERR_PRECONDITION_FAILED, // []
/** A string supplied was too long */
ERR_PRECONDITION_STRING_TOO_LONG, // []
+ /** A string had too many parameters */
+ ERR_PRECONDITION_TOO_MANY_PARAMETERS, // []
/** The company you use is invalid */
ERR_PRECONDITION_INVALID_COMPANY, // []
/** An error returned by a NewGRF. No possibility to get the exact error in an script readable format */