From 36967b32fd02eaab4273c1a1e7a1210a5fe45d09 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Mon, 17 Aug 2020 21:41:02 +0200 Subject: patch 8.2.1475: Vim9: can't use v:true for option flags Problem: Vim9: can't use v:true for option flags. Solution: Add tv_get_bool_chk(). (closes #6725) --- src/typval.c | 55 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/typval.c') 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) -- cgit v1.2.1