-
-
Notifications
You must be signed in to change notification settings - Fork 2
Tips for creating custom functions
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.
This should be used in the following cases:
- Arguments are not of the required size, either below or above your limit
- A for loop has ended without returning
- An index is higher or equal to the size of an array
Return this if a value is invalid and was not what was expected.
Return this if one or more types are not what was expected.
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
.
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.
This project is supported by all the people who joined our discord server and became beta testers. If you want to join the discord you can click here