diff src/evalvars.c @ 20731:ab27db64f1fb v8.2.0918

patch 8.2.0918: duplicate code for evaluating expression argument Commit: https://github.com/vim/vim/commit/a9c010494767e43a51c443cac35ebc80d0831d0b Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 7 14:50:50 2020 +0200 patch 8.2.0918: duplicate code for evaluating expression argument Problem: Duplicate code for evaluating expression argument. Solution: Merge the code and make the use more flexible.
author Bram Moolenaar <Bram@vim.org>
date Sun, 07 Jun 2020 15:00:04 +0200
parents f4455c71a8aa
children 9faab49c880f
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3811,79 +3811,4 @@ free_callback(callback_T *callback)
     callback->cb_name = NULL;
 }
 
-/*
- * Process a function argument that can be a string expression or a function
- * reference.
- * "tv" must remain valid until calling evalarg_clean()!
- * Returns FAIL when the argument is invalid.
- */
-    int
-evalarg_get(typval_T *tv, evalarg_T *eva)
-{
-    if (tv->v_type == VAR_STRING
-	    || tv->v_type == VAR_NUMBER
-	    || tv->v_type == VAR_BOOL
-	    || tv->v_type == VAR_SPECIAL)
-    {
-	eva->eva_string = tv_get_string_buf(tv, eva->eva_buf);
-	return OK;
-    }
-
-    eva->eva_callback = get_callback(tv);
-    return eva->eva_callback.cb_name == NULL ? FAIL : OK;
-}
-
-/*
- * Return whether "eva" has a valid expression or callback.
- */
-    int
-evalarg_valid(evalarg_T *eva)
-{
-    return eva->eva_string != NULL || eva->eva_callback.cb_name != NULL;
-}
-
-/*
- * Invoke the expression or callback "eva" and return the result in "tv".
- * Returns FAIL if something failed
- */
-    int
-evalarg_call(evalarg_T *eva, typval_T *tv)
-{
-    typval_T	argv[1];
-
-    if (eva->eva_string != NULL)
-	return eval0(eva->eva_string, tv, NULL, EVAL_EVALUATE);
-
-    argv[0].v_type = VAR_UNKNOWN;
-    return call_callback(&eva->eva_callback, -1, tv, 0, argv);
-}
-
-/*
- * Like evalarg_call(), but just return TRUE of FALSE.
- * Sets "error" to TRUE if evaluation failed.
- */
-    int
-evalarg_call_bool(evalarg_T *eva, int *error)
-{
-    typval_T	tv;
-    int		r;
-
-    if (evalarg_call(eva, &tv) == FAIL)
-    {
-	*error = TRUE;
-	return FALSE;
-    }
-    r = tv_get_number(&tv);
-    clear_tv(&tv);
-    *error = FALSE;
-    return r;
-}
-
-    void
-evalarg_clean(evalarg_T *eva)
-{
-    if (eva->eva_string == NULL)
-	free_callback(&eva->eva_callback);
-}
-
 #endif // FEAT_EVAL