comparison src/getchar.c @ 24838:3f9053c21765 v8.2.2957

patch 8.2.2957: using getchar() in Vim9 script is problematic Commit: https://github.com/vim/vim/commit/3a7503c34c65ed15cc08deb5b54aaf2ea51525b4 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jun 7 18:29:17 2021 +0200 patch 8.2.2957: using getchar() in Vim9 script is problematic Problem: Using getchar() in Vim9 script is problematic. Solution: Add getcharstr(). (closes https://github.com/vim/vim/issues/8343)
author Bram Moolenaar <Bram@vim.org>
date Mon, 07 Jun 2021 18:30:04 +0200
parents 826ba03d0d22
children fdc6a7769045
comparison
equal deleted inserted replaced
24837:a9c9ff4fb89b 24838:3f9053c21765
2014 return (retval != NUL); 2014 return (retval != NUL);
2015 } 2015 }
2016 2016
2017 #if defined(FEAT_EVAL) || defined(PROTO) 2017 #if defined(FEAT_EVAL) || defined(PROTO)
2018 /* 2018 /*
2019 * "getchar()" function 2019 * "getchar()" and "getcharstr()" functions
2020 */ 2020 */
2021 void 2021 static void
2022 f_getchar(typval_T *argvars, typval_T *rettv) 2022 getchar_common(typval_T *argvars, typval_T *rettv)
2023 { 2023 {
2024 varnumber_T n; 2024 varnumber_T n;
2025 int error = FALSE; 2025 int error = FALSE;
2026 2026
2027 #ifdef MESSAGE_QUEUE 2027 #ifdef MESSAGE_QUEUE
2121 set_vim_var_nr(VV_MOUSE_WINID, win->w_id); 2121 set_vim_var_nr(VV_MOUSE_WINID, win->w_id);
2122 set_vim_var_nr(VV_MOUSE_LNUM, lnum); 2122 set_vim_var_nr(VV_MOUSE_LNUM, lnum);
2123 set_vim_var_nr(VV_MOUSE_COL, col + 1); 2123 set_vim_var_nr(VV_MOUSE_COL, col + 1);
2124 } 2124 }
2125 } 2125 }
2126 }
2127 }
2128
2129 /*
2130 * "getchar()" function
2131 */
2132 void
2133 f_getchar(typval_T *argvars, typval_T *rettv)
2134 {
2135 getchar_common(argvars, rettv);
2136 }
2137
2138 /*
2139 * "getcharstr()" function
2140 */
2141 void
2142 f_getcharstr(typval_T *argvars, typval_T *rettv)
2143 {
2144 getchar_common(argvars, rettv);
2145
2146 if (rettv->v_type == VAR_NUMBER)
2147 {
2148 char_u temp[7]; // mbyte-char: 6, NUL: 1
2149 varnumber_T n = rettv->vval.v_number;
2150 int i = 0;
2151
2152 if (n != 0)
2153 {
2154 if (has_mbyte)
2155 i += (*mb_char2bytes)(n, temp + i);
2156 else
2157 temp[i++] = n;
2158 }
2159 temp[i++] = NUL;
2160 rettv->v_type = VAR_STRING;
2161 rettv->vval.v_string = vim_strsave(temp);
2126 } 2162 }
2127 } 2163 }
2128 2164
2129 /* 2165 /*
2130 * "getcharmod()" function 2166 * "getcharmod()" function