Reporting errors

Due to the weakly typed nature of the parser, and the fact that functions receive arguments as an array with variable length, it's important to do proper error checking.

Since functions return a Variable, setting its status member to any value other than UTTE_PARSE_STATUS_SUCCESS will produce an error and stop the parser. This section explains how to use the different error codes.

Errors can easily be returned by using the UTTE_ERROR macro and passing an error as its argument.

UTTE_PARSE_STATUS_OUT_OF_BOUNDS

This should be used in the following cases:

  1. Arguments are not of the required size, either below or above your limit
  2. A for loop has ended without returning
  3. An index is higher or equal to the size of an array

UTTE_PARSE_STATUS_INVALID_VALUE

Return this if a value is invalid and was not what was expected.

UTTE_PARSE_STATUS_INVALID_TYPE

Return this if one or more types are not what was expected.

Checking if a variable is a boolean expression

The UTTE::CoreFuncs::getBooleanV function takes a string as an argument and returns a boolean with the value of the boolean string. Works with booleans represented as numbers and as words like true and false.

Additionally, a C version exists that takes a const char*, named UTTE_CoreFuncts_getBooleanV.

Getting an array or map from a variable

The UTTE::CoreFuncs::getArray and UTTE::CoreFuncs::getMap functions return a pointer to an array or map from a reference to a Variable. They return nullptr if the type does not match or the underlying value is a nullptr.

Additionally, C versions with the same name exist. However, their memory has to manually be freed using UTTE_CoreFuncs_freeArray for arrays or UTTE_CoreFuncs_freeMap for maps.