summaryrefslogtreecommitdiff
path: root/src/typval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-17 21:41:02 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-17 21:41:02 +0200
commit36967b32fd02eaab4273c1a1e7a1210a5fe45d09 (patch)
tree34de67c1d4d14063179da865bd40c6982fc29904 /src/typval.c
parent624b6eaf20f3e8c669425b6a32f17fb9ec2ebbd2 (diff)
downloadvim-git-36967b32fd02eaab4273c1a1e7a1210a5fe45d09.tar.gz
patch 8.2.1475: Vim9: can't use v:true for option flagsv8.2.1475
Problem: Vim9: can't use v:true for option flags. Solution: Add tv_get_bool_chk(). (closes #6725)
Diffstat (limited to 'src/typval.c')
-rw-r--r--src/typval.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/src/typval.c b/src/typval.c
index 406a193be..053f30077 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -169,24 +169,8 @@ init_tv(typval_T *varp)
CLEAR_POINTER(varp);
}
-/*
- * Get the number value of a variable.
- * If it is a String variable, uses vim_str2nr().
- * For incompatible types, return 0.
- * tv_get_number_chk() is similar to tv_get_number(), but informs the
- * caller of incompatible types: it sets *denote to TRUE if "denote"
- * is not NULL or returns -1 otherwise.
- */
- varnumber_T
-tv_get_number(typval_T *varp)
-{
- int error = FALSE;
-
- return tv_get_number_chk(varp, &error); // return 0L on error
-}
-
- varnumber_T
-tv_get_number_chk(typval_T *varp, int *denote)
+ static varnumber_T
+tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool)
{
varnumber_T n = 0L;
@@ -221,7 +205,7 @@ tv_get_number_chk(typval_T *varp, int *denote)
break;
case VAR_BOOL:
case VAR_SPECIAL:
- if (in_vim9script())
+ if (!want_bool && in_vim9script())
{
emsg(_("E611: Using a Special as a Number"));
break;
@@ -253,6 +237,39 @@ tv_get_number_chk(typval_T *varp, int *denote)
return n;
}
+/*
+ * Get the number value of a variable.
+ * If it is a String variable, uses vim_str2nr().
+ * For incompatible types, return 0.
+ * tv_get_number_chk() is similar to tv_get_number(), but informs the
+ * caller of incompatible types: it sets *denote to TRUE if "denote"
+ * is not NULL or returns -1 otherwise.
+ */
+ varnumber_T
+tv_get_number(typval_T *varp)
+{
+ int error = FALSE;
+
+ return tv_get_number_chk(varp, &error); // return 0L on error
+}
+
+ varnumber_T
+tv_get_number_chk(typval_T *varp, int *denote)
+{
+ return tv_get_bool_or_number_chk(varp, denote, FALSE);
+}
+
+/*
+ * Get the boolean value of "varp". This is like tv_get_number_chk(),
+ * but in Vim9 script accepts Number and Bool.
+ */
+ varnumber_T
+tv_get_bool(typval_T *varp)
+{
+ return tv_get_bool_or_number_chk(varp, NULL, TRUE);
+
+}
+
#ifdef FEAT_FLOAT
float_T
tv_get_float(typval_T *varp)