GLOBAL int Expr_Eval_Bool(const char* str, const parser_extra* f, int *result) { int err; expr_val e; e = Expr_Eval(str, f, &err); if (err == EXPR_EVAL_SUCCESS) *result = Get_Bool(e); return err; }
void Cvar_Set_Eval_f(void) { if (Cmd_Argc() < 3) { Com_Printf("Usage:\n" "set_eval <variable> <expression>\n" "set_eval is similar to set_calc but supports richer expressions\n"); return; } else { const char *expression; char *var_name; cvar_t *var; int errn; expr_val result; var_name = Cmd_Argv (1); var = Cvar_Find (var_name); if (!var) var = Cvar_Create (var_name, Cmd_Argv (1), 0); expression = Cmd_MakeArgs(2); result = Expr_Eval(expression, NULL, &errn); if (errn == EXPR_EVAL_SUCCESS) { switch (result.type) { case ET_INT: Cvar_SetValue(var, result.i_val); break; case ET_DBL: Cvar_SetValue(var, result.d_val); break; case ET_BOOL: Cvar_SetValue(var, result.b_val ? 1 : 0); break; case ET_STR: Cvar_Set(var, result.s_val); free(result.s_val); break; } } else { Com_Printf("Error in expression: %s\n", Parser_Error_Description(errn)); } } }