diff --git a/lib/dice.c b/lib/dice.c index 7f34b3f..b2f66a9 100644 --- a/lib/dice.c +++ b/lib/dice.c @@ -154,6 +154,15 @@ bool dice_set(dice_t d, dice_option_t opt, ...) 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, ...) { va_list lst; diff --git a/lib/dice.h b/lib/dice.h index 487b82c..ba9e214 100644 --- a/lib/dice.h +++ b/lib/dice.h @@ -101,6 +101,12 @@ bool dice_set(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. */ int64_t dice_roll(dice_t d);