summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2011-06-19 02:55:37 +0200
committerBram Moolenaar <Bram@vim.org>2011-06-19 02:55:37 +0200
commit5f8949656acb8b2a850d59f685865938862e4f6d (patch)
treef5ea02a3df12d9c551d6ea5f6eb9c54a3c2e5929 /src/eval.c
parentc16756d82968d31ec3927ff1320f5f8fa5d7dbf3 (diff)
downloadvim-5f8949656acb8b2a850d59f685865938862e4f6d.zip
updated for version 7.3.224
Problem: Can't pass dict to sort function. Solution: Add the optional {dict} argument to sort(). (ZyX)
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c
index a1912fd3c..648d938dc 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -7930,7 +7930,7 @@ static struct fst
{"sin", 1, 1, f_sin},
{"sinh", 1, 1, f_sinh},
#endif
- {"sort", 1, 2, f_sort},
+ {"sort", 1, 3, f_sort},
{"soundfold", 1, 1, f_soundfold},
{"spellbadword", 0, 1, f_spellbadword},
{"spellsuggest", 1, 3, f_spellsuggest},
@@ -16366,6 +16366,7 @@ static int
static int item_compare_ic;
static char_u *item_compare_func;
+static dict_T *item_compare_selfdict;
static int item_compare_func_err;
#define ITEM_COMPARE_FAIL 999
@@ -16425,7 +16426,8 @@ item_compare2(s1, s2)
rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */
res = call_func(item_compare_func, (int)STRLEN(item_compare_func),
- &rettv, 2, argv, 0L, 0L, &dummy, TRUE, NULL);
+ &rettv, 2, argv, 0L, 0L, &dummy, TRUE,
+ item_compare_selfdict);
clear_tv(&argv[0]);
clear_tv(&argv[1]);
@@ -16471,8 +16473,10 @@ f_sort(argvars, rettv)
item_compare_ic = FALSE;
item_compare_func = NULL;
+ item_compare_selfdict = NULL;
if (argvars[1].v_type != VAR_UNKNOWN)
{
+ /* optional second argument: {func} */
if (argvars[1].v_type == VAR_FUNC)
item_compare_func = argvars[1].vval.v_string;
else
@@ -16487,6 +16491,17 @@ f_sort(argvars, rettv)
else
item_compare_func = get_tv_string(&argvars[1]);
}
+
+ if (argvars[2].v_type != VAR_UNKNOWN)
+ {
+ /* optional third argument: {dict} */
+ if (argvars[2].v_type != VAR_DICT)
+ {
+ EMSG(_(e_dictreq));
+ return;
+ }
+ item_compare_selfdict = argvars[2].vval.v_dict;
+ }
}
/* Make an array with each entry pointing to an item in the List. */