change API of expression to be consistent with dice API
This commit is contained in:
@@ -55,9 +55,11 @@ bool dice_get(dice_t d, dice_option_t opt, ...);
|
||||
int64_t dice_roll(dice_t d);
|
||||
bool dice_evaluate(dice_t d, dice_result_t **res, size_t *reslen);
|
||||
|
||||
dice_expression_t dice_expression_parse(char const *s, int *error);
|
||||
dice_expression_t dice_expression_new(void);
|
||||
void dice_expression_free(dice_expression_t e);
|
||||
bool dice_expression_evaluate(dice_expression_t e, int64_t *result);
|
||||
|
||||
bool dice_expression_parse(dice_expression_t d, char const *s, int *error);
|
||||
bool dice_expression_roll(dice_expression_t e, int64_t *result);
|
||||
bool dice_expression_print(dice_expression_t e);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -729,7 +729,7 @@ void dice_expression_free(dice_expression_t e)
|
||||
free(e);
|
||||
}
|
||||
|
||||
dice_expression_t dice_expression_parse(char const *n, int *error)
|
||||
dice_expression_t dice_expression_new(void)
|
||||
{
|
||||
dice_expression_t e = NULL;
|
||||
|
||||
@@ -738,16 +738,27 @@ dice_expression_t dice_expression_parse(char const *n, int *error)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
e->expr = te_compile(n, 0, 0, error);
|
||||
if (e->expr == NULL) {
|
||||
free(e);
|
||||
return NULL;
|
||||
}
|
||||
e->expr = NULL;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
bool dice_expression_evaluate(dice_expression_t e, int64_t *result)
|
||||
bool dice_expression_parse(dice_expression_t e, char const *n, int *error)
|
||||
{
|
||||
if (e->expr != NULL) {
|
||||
te_free(e->expr);
|
||||
e->expr = NULL;
|
||||
}
|
||||
|
||||
e->expr = te_compile(n, 0, 0, error);
|
||||
if (e->expr == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dice_expression_roll(dice_expression_t e, int64_t *result)
|
||||
{
|
||||
double val;
|
||||
if (e == NULL || e->expr == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user