add a convenience function dice_errstr

This commit is contained in:
Florian Stinglmayr 2018-03-23 18:49:20 +01:00
parent 85810123a2
commit f206597347
2 changed files with 15 additions and 0 deletions

View File

@ -154,6 +154,15 @@ bool dice_set(dice_t d, dice_option_t opt, ...)
return true; return true;
} }
char const * dice_errstr(dice_t d)
{
if (d == NULL || d->error == NULL) {
return NULL;
}
return d->error;
}
bool dice_get(dice_t d, dice_option_t opt, ...) bool dice_get(dice_t d, dice_option_t opt, ...)
{ {
va_list lst; va_list lst;

View File

@ -101,6 +101,12 @@ bool dice_set(dice_t d, dice_option_t opt, ...);
*/ */
bool dice_get(dice_t d, dice_option_t opt, ...); bool dice_get(dice_t d, dice_option_t opt, ...);
/* Returns the error string that was encountered while parsing. This is
* the same as calling dice_get() with the DICEOPTION_ERROR option set.
* It is meant as convenience function.
*/
char const * dice_errstr(dice_t d);
/* Rolls the given dice object once, and returns the result. /* Rolls the given dice object once, and returns the result.
*/ */
int64_t dice_roll(dice_t d); int64_t dice_roll(dice_t d);