Mercurial > vim
diff src/typval.c @ 21851:727820154b1a v8.2.1475
patch 8.2.1475: Vim9: can't use v:true for option flags
Commit: https://github.com/vim/vim/commit/36967b32fd02eaab4273c1a1e7a1210a5fe45d09
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Aug 17 21:41:02 2020 +0200
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 https://github.com/vim/vim/issues/6725)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 17 Aug 2020 21:45:03 +0200 |
parents | d8422de73113 |
children | cd8dafe937ba |
line wrap: on
line diff
--- 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 *d 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 *d 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)