blob: 05977b641c879aa72397c77b693b9517119348cf [file] [log] [blame]
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * vim9script.c: :vim9script, :import, :export and friends
12 */
13
14#include "vim.h"
15
Bram Moolenaar9b8d6222020-12-28 18:26:00 +010016#if defined(FEAT_EVAL)
17# include "vim9.h"
18#endif
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010019
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010020 int
21in_vim9script(void)
22{
Bram Moolenaareb6880b2020-07-12 17:07:05 +020023 // Do not go up the stack, a ":function" inside vim9script uses legacy
24 // syntax. "sc_version" is also set when compiling a ":def" function in
25 // legacy script.
Bram Moolenaar9979fcd2021-02-14 13:30:01 +010026 return current_sctx.sc_version == SCRIPT_VERSION_VIM9
27 || (cmdmod.cmod_flags & CMOD_VIM9CMD);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010028}
29
30/*
31 * ":vim9script".
32 */
33 void
Bram Moolenaar9b8d6222020-12-28 18:26:00 +010034ex_vim9script(exarg_T *eap UNUSED)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010035{
Bram Moolenaar9b8d6222020-12-28 18:26:00 +010036#ifdef FEAT_EVAL
Bram Moolenaar2b327002020-12-26 15:39:31 +010037 int sid = current_sctx.sc_sid;
Bram Moolenaar101f4812020-06-16 23:18:51 +020038 scriptitem_T *si;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010039
40 if (!getline_equal(eap->getline, eap->cookie, getsourceline))
41 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +020042 emsg(_(e_vim9script_can_only_be_used_in_script));
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010043 return;
44 }
Bram Moolenaar2b327002020-12-26 15:39:31 +010045
46 si = SCRIPT_ITEM(sid);
47 if (si->sn_state == SN_STATE_HAD_COMMAND)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010048 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +020049 emsg(_(e_vim9script_must_be_first_command_in_script));
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010050 return;
51 }
Bram Moolenaar2b327002020-12-26 15:39:31 +010052 if (!IS_WHITE_OR_NUL(*eap->arg) && STRCMP(eap->arg, "noclear") != 0)
53 {
54 semsg(_(e_invarg2), eap->arg);
55 return;
56 }
57 if (si->sn_state == SN_STATE_RELOAD && IS_WHITE_OR_NUL(*eap->arg))
58 {
59 hashtab_T *ht = &SCRIPT_VARS(sid);
60
61 // Reloading a script without the "noclear" argument: clear
62 // script-local variables and functions.
63 hashtab_free_contents(ht);
64 hash_init(ht);
65 delete_script_functions(sid);
66
67 // old imports and script variables are no longer valid
68 free_imports_and_script_vars(sid);
69 }
70 si->sn_state = SN_STATE_HAD_COMMAND;
71
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010072 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
73 si->sn_version = SCRIPT_VERSION_VIM9;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010074
75 if (STRCMP(p_cpo, CPO_VIM) != 0)
76 {
Bram Moolenaar39ca4122020-10-20 14:25:07 +020077 si->sn_save_cpo = vim_strsave(p_cpo);
Bram Moolenaar37294bd2021-03-10 13:40:08 +010078 set_option_value((char_u *)"cpo", 0L, (char_u *)CPO_VIM, OPT_NO_REDRAW);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010079 }
Bram Moolenaar9b8d6222020-12-28 18:26:00 +010080#else
81 // No check for this being the first command, it doesn't matter.
82 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
83#endif
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010084}
85
86/*
Bram Moolenaarae616492020-07-28 20:07:27 +020087 * When in Vim9 script give an error and return FAIL.
88 */
89 int
90not_in_vim9(exarg_T *eap)
91{
Bram Moolenaar68e30442020-07-28 21:15:07 +020092 if (in_vim9script())
93 switch (eap->cmdidx)
94 {
Bram Moolenaarada1d872021-02-20 08:16:51 +010095 case CMD_k:
96 if (eap->addr_count > 0)
97 {
98 emsg(_(e_norange));
99 return FAIL;
100 }
101 // FALLTHROUGH
Bram Moolenaar68e30442020-07-28 21:15:07 +0200102 case CMD_append:
103 case CMD_change:
Bram Moolenaarf5a48012020-08-01 17:00:03 +0200104 case CMD_insert:
Bram Moolenaar65088802021-03-13 21:07:21 +0100105 case CMD_open:
Bram Moolenaarf5a48012020-08-01 17:00:03 +0200106 case CMD_t:
Bram Moolenaar68e30442020-07-28 21:15:07 +0200107 case CMD_xit:
Bram Moolenaar9b8d6222020-12-28 18:26:00 +0100108 semsg(_(e_command_not_supported_in_vim9_script_missing_var_str), eap->cmd);
Bram Moolenaar68e30442020-07-28 21:15:07 +0200109 return FAIL;
110 default: break;
111 }
Bram Moolenaarae616492020-07-28 20:07:27 +0200112 return OK;
113}
114
Bram Moolenaardcc58e02020-12-28 20:53:21 +0100115/*
116 * Return TRUE if "p" points at a "#". Does not check for white space.
117 */
118 int
119vim9_comment_start(char_u *p)
120{
121 return p[0] == '#';
122}
123
Bram Moolenaar9b8d6222020-12-28 18:26:00 +0100124#if defined(FEAT_EVAL) || defined(PROTO)
125
Bram Moolenaarae616492020-07-28 20:07:27 +0200126/*
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100127 * ":export let Name: type"
128 * ":export const Name: type"
129 * ":export def Name(..."
130 * ":export class Name ..."
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100131 */
132 void
Bram Moolenaar09689a02020-05-09 22:50:08 +0200133ex_export(exarg_T *eap)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100134{
Bram Moolenaareb6880b2020-07-12 17:07:05 +0200135 if (!in_vim9script())
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100136 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +0200137 emsg(_(e_export_can_only_be_used_in_vim9script));
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100138 return;
139 }
140
141 eap->cmd = eap->arg;
Bram Moolenaar2e2d7582021-03-03 21:22:41 +0100142 (void)find_ex_command(eap, NULL, lookup_scriptitem, NULL);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100143 switch (eap->cmdidx)
144 {
145 case CMD_let:
Bram Moolenaar30fd8202020-09-26 15:09:30 +0200146 case CMD_var:
147 case CMD_final:
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100148 case CMD_const:
149 case CMD_def:
150 // case CMD_class:
151 is_export = TRUE;
152 do_cmdline(eap->cmd, eap->getline, eap->cookie,
153 DOCMD_VERBOSE + DOCMD_NOWAIT);
154
155 // The command will reset "is_export" when exporting an item.
156 if (is_export)
157 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +0200158 emsg(_(e_export_with_invalid_argument));
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100159 is_export = FALSE;
160 }
161 break;
162 default:
Bram Moolenaar451c2e32020-08-15 16:33:28 +0200163 emsg(_(e_invalid_command_after_export));
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100164 break;
165 }
166}
167
168/*
169 * Add a new imported item entry to the current script.
170 */
171 static imported_T *
172new_imported(garray_T *gap)
173{
174 if (ga_grow(gap, 1) == OK)
175 return ((imported_T *)gap->ga_data + gap->ga_len++);
176 return NULL;
177}
178
179/*
180 * Free all imported items in script "sid".
181 */
182 void
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200183free_imports_and_script_vars(int sid)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100184{
Bram Moolenaar21b9e972020-01-26 19:26:46 +0100185 scriptitem_T *si = SCRIPT_ITEM(sid);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100186 int idx;
187
188 for (idx = 0; idx < si->sn_imports.ga_len; ++idx)
189 {
Bram Moolenaar20431c92020-03-20 18:39:46 +0100190 imported_T *imp = ((imported_T *)si->sn_imports.ga_data) + idx;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100191
192 vim_free(imp->imp_name);
193 }
194 ga_clear(&si->sn_imports);
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200195
196 free_all_script_vars(si);
197
Bram Moolenaar6110e792020-07-08 19:35:21 +0200198 clear_type_list(&si->sn_type_list);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100199}
200
201/*
Bram Moolenaara6294952020-12-27 13:39:50 +0100202 * Mark all imports as possible to redefine. Used when a script is loaded
203 * again but not cleared.
204 */
205 void
206mark_imports_for_reload(int sid)
207{
208 scriptitem_T *si = SCRIPT_ITEM(sid);
209 int idx;
210
211 for (idx = 0; idx < si->sn_imports.ga_len; ++idx)
212 {
213 imported_T *imp = ((imported_T *)si->sn_imports.ga_data) + idx;
214
215 imp->imp_flags |= IMP_FLAGS_RELOAD;
216 }
217}
218
219/*
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100220 * ":import Item from 'filename'"
221 * ":import Item as Alias from 'filename'"
222 * ":import {Item} from 'filename'".
223 * ":import {Item as Alias} from 'filename'"
224 * ":import {Item, Item} from 'filename'"
225 * ":import {Item, Item as Alias} from 'filename'"
226 *
227 * ":import * as Name from 'filename'"
228 */
229 void
230ex_import(exarg_T *eap)
231{
Bram Moolenaar1c991142020-07-04 13:15:31 +0200232 char_u *cmd_end;
233 evalarg_T evalarg;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100234
Bram Moolenaar101f4812020-06-16 23:18:51 +0200235 if (!getline_equal(eap->getline, eap->cookie, getsourceline))
236 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +0200237 emsg(_(e_import_can_only_be_used_in_script));
Bram Moolenaar101f4812020-06-16 23:18:51 +0200238 return;
239 }
Bram Moolenaar1c991142020-07-04 13:15:31 +0200240 fill_evalarg_from_eap(&evalarg, eap, eap->skip);
Bram Moolenaar101f4812020-06-16 23:18:51 +0200241
Bram Moolenaar1c991142020-07-04 13:15:31 +0200242 cmd_end = handle_import(eap->arg, NULL, current_sctx.sc_sid,
243 &evalarg, NULL);
Bram Moolenaar9721fb42020-06-11 23:10:46 +0200244 if (cmd_end != NULL)
245 eap->nextcmd = check_nextcmd(cmd_end);
Bram Moolenaar1c991142020-07-04 13:15:31 +0200246 clear_evalarg(&evalarg, eap);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100247}
248
249/*
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100250 * Find an exported item in "sid" matching the name at "*argp".
251 * When it is a variable return the index.
252 * When it is a user function return "*ufunc".
253 * When not found returns -1 and "*ufunc" is NULL.
254 */
255 int
256find_exported(
257 int sid,
Bram Moolenaar1c991142020-07-04 13:15:31 +0200258 char_u *name,
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100259 ufunc_T **ufunc,
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200260 type_T **type,
Bram Moolenaarcb4e80f2021-03-13 20:57:19 +0100261 cctx_T *cctx,
262 int verbose)
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100263{
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100264 int idx = -1;
265 svar_T *sv;
266 scriptitem_T *script = SCRIPT_ITEM(sid);
267
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100268 // find name in "script"
269 // TODO: also find script-local user function
Bram Moolenaar08251752021-01-11 21:20:18 +0100270 idx = get_script_item_idx(sid, name, 0, cctx);
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100271 if (idx >= 0)
272 {
273 sv = ((svar_T *)script->sn_var_vals.ga_data) + idx;
274 if (!sv->sv_export)
275 {
Bram Moolenaarcb4e80f2021-03-13 20:57:19 +0100276 if (verbose)
277 semsg(_(e_item_not_exported_in_script_str), name);
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100278 return -1;
279 }
280 *type = sv->sv_type;
281 *ufunc = NULL;
282 }
283 else
284 {
285 char_u buffer[200];
286 char_u *funcname;
287
288 // it could be a user function.
Bram Moolenaar5a67c372020-07-23 14:39:47 +0200289 if (STRLEN(name) < sizeof(buffer) - 15)
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100290 funcname = buffer;
291 else
292 {
Bram Moolenaar5a67c372020-07-23 14:39:47 +0200293 funcname = alloc(STRLEN(name) + 15);
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100294 if (funcname == NULL)
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100295 return -1;
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100296 }
297 funcname[0] = K_SPECIAL;
298 funcname[1] = KS_EXTRA;
299 funcname[2] = (int)KE_SNR;
300 sprintf((char *)funcname + 3, "%ld_%s", (long)sid, name);
Bram Moolenaar4c17ad92020-04-27 22:47:51 +0200301 *ufunc = find_func(funcname, FALSE, NULL);
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100302 if (funcname != buffer)
303 vim_free(funcname);
304
305 if (*ufunc == NULL)
306 {
Bram Moolenaarcb4e80f2021-03-13 20:57:19 +0100307 if (verbose)
308 semsg(_(e_item_not_found_in_script_str), name);
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100309 return -1;
310 }
311 }
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100312
313 return idx;
314}
315
316/*
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100317 * Handle an ":import" command and add the resulting imported_T to "gap", when
318 * not NULL, or script "import_sid" sn_imports.
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200319 * "cctx" is NULL at the script level.
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100320 * Returns a pointer to after the command or NULL in case of failure
321 */
322 char_u *
Bram Moolenaar1c991142020-07-04 13:15:31 +0200323handle_import(
324 char_u *arg_start,
325 garray_T *gap,
326 int import_sid,
327 evalarg_T *evalarg,
328 void *cctx)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100329{
330 char_u *arg = arg_start;
Bram Moolenaar1c991142020-07-04 13:15:31 +0200331 char_u *cmd_end = NULL;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100332 int ret = FAIL;
333 typval_T tv;
334 int sid = -1;
335 int res;
Bram Moolenaar0a842842021-02-27 22:41:19 +0100336 int mult = FALSE;
Bram Moolenaar1c991142020-07-04 13:15:31 +0200337 garray_T names;
Bram Moolenaar0a842842021-02-27 22:41:19 +0100338 garray_T as_names;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100339
Bram Moolenaar1c991142020-07-04 13:15:31 +0200340 ga_init2(&names, sizeof(char_u *), 10);
Bram Moolenaar0a842842021-02-27 22:41:19 +0100341 ga_init2(&as_names, sizeof(char_u *), 10);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100342 if (*arg == '{')
343 {
Bram Moolenaar1c991142020-07-04 13:15:31 +0200344 // "import {item, item} from ..."
Bram Moolenaar0a842842021-02-27 22:41:19 +0100345 mult = TRUE;
Bram Moolenaar1c991142020-07-04 13:15:31 +0200346 arg = skipwhite_and_linebreak(arg + 1, evalarg);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100347 }
Bram Moolenaar1c991142020-07-04 13:15:31 +0200348
Bram Moolenaar0a842842021-02-27 22:41:19 +0100349 for (;;)
350 {
351 char_u *p = arg;
352 int had_comma = FALSE;
353 char_u *as_name = NULL;
354
355 // accept "*" or "Name"
356 if (!mult && arg[0] == '*' && IS_WHITE_OR_NUL(arg[1]))
357 ++arg;
358 else
Bram Moolenaarfa29c8a2020-02-23 22:35:05 +0100359 while (eval_isnamec(*arg))
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100360 ++arg;
Bram Moolenaar0a842842021-02-27 22:41:19 +0100361 if (p == arg)
362 break;
363 if (ga_grow(&names, 1) == FAIL || ga_grow(&as_names, 1) == FAIL)
Bram Moolenaar1c991142020-07-04 13:15:31 +0200364 goto erret;
Bram Moolenaar0a842842021-02-27 22:41:19 +0100365 ((char_u **)names.ga_data)[names.ga_len] = vim_strnsave(p, arg - p);
366 ++names.ga_len;
Bram Moolenaar1c991142020-07-04 13:15:31 +0200367
Bram Moolenaar0a842842021-02-27 22:41:19 +0100368 arg = skipwhite_and_linebreak(arg, evalarg);
Bram Moolenaar1c991142020-07-04 13:15:31 +0200369 if (STRNCMP("as", arg, 2) == 0 && IS_WHITE_OR_NUL(arg[2]))
370 {
Bram Moolenaar1c991142020-07-04 13:15:31 +0200371 // skip over "as Name "; no line break allowed after "as"
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100372 arg = skipwhite(arg + 2);
Bram Moolenaar1c991142020-07-04 13:15:31 +0200373 p = arg;
Bram Moolenaarfa29c8a2020-02-23 22:35:05 +0100374 if (eval_isnamec1(*arg))
375 while (eval_isnamec(*arg))
376 ++arg;
Bram Moolenaar057e84a2021-02-28 16:55:11 +0100377 if (check_defined(p, arg - p, cctx, FALSE) == FAIL)
Bram Moolenaar1c991142020-07-04 13:15:31 +0200378 goto erret;
379 as_name = vim_strnsave(p, arg - p);
380 arg = skipwhite_and_linebreak(arg, evalarg);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100381 }
382 else if (*arg_start == '*')
383 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +0200384 emsg(_(e_missing_as_after_star));
Bram Moolenaar1c991142020-07-04 13:15:31 +0200385 goto erret;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100386 }
Bram Moolenaar0a842842021-02-27 22:41:19 +0100387 // without "as Name" the as_names entry is NULL
388 ((char_u **)as_names.ga_data)[as_names.ga_len] = as_name;
389 ++as_names.ga_len;
390
391 if (!mult)
392 break;
393 if (*arg == ',')
394 {
395 had_comma = TRUE;
396 ++arg;
397 }
398 arg = skipwhite_and_linebreak(arg, evalarg);
399 if (*arg == '}')
400 {
401 ++arg;
402 break;
403 }
404 if (!had_comma)
405 {
406 emsg(_(e_missing_comma_in_import));
407 goto erret;
408 }
409 }
410 arg = skipwhite_and_linebreak(arg, evalarg);
411
412 if (names.ga_len == 0)
413 {
414 emsg(_(e_syntax_error_in_import));
415 goto erret;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100416 }
Bram Moolenaar1c991142020-07-04 13:15:31 +0200417
418 if (STRNCMP("from", arg, 4) != 0 || !IS_WHITE_OR_NUL(arg[4]))
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100419 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +0200420 emsg(_(e_missing_from));
Bram Moolenaar1c991142020-07-04 13:15:31 +0200421 goto erret;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100422 }
Bram Moolenaar1c991142020-07-04 13:15:31 +0200423
Bram Moolenaar962d7212020-07-04 14:15:00 +0200424 arg = skipwhite_and_linebreak(arg + 4, evalarg);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100425 tv.v_type = VAR_UNKNOWN;
426 // TODO: should we accept any expression?
427 if (*arg == '\'')
Bram Moolenaar9a78e6d2020-07-01 18:29:55 +0200428 ret = eval_lit_string(&arg, &tv, TRUE);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100429 else if (*arg == '"')
Bram Moolenaar9a78e6d2020-07-01 18:29:55 +0200430 ret = eval_string(&arg, &tv, TRUE);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100431 if (ret == FAIL || tv.vval.v_string == NULL || *tv.vval.v_string == NUL)
432 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +0200433 emsg(_(e_invalid_string_after_from));
Bram Moolenaar1c991142020-07-04 13:15:31 +0200434 goto erret;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100435 }
436 cmd_end = arg;
437
Bram Moolenaar1c991142020-07-04 13:15:31 +0200438 /*
439 * find script file
440 */
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100441 if (*tv.vval.v_string == '.')
442 {
443 size_t len;
Bram Moolenaar21b9e972020-01-26 19:26:46 +0100444 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100445 char_u *tail = gettail(si->sn_name);
446 char_u *from_name;
447
448 // Relative to current script: "./name.vim", "../../name.vim".
449 len = STRLEN(si->sn_name) - STRLEN(tail) + STRLEN(tv.vval.v_string) + 2;
450 from_name = alloc((int)len);
451 if (from_name == NULL)
452 {
453 clear_tv(&tv);
Bram Moolenaar1c991142020-07-04 13:15:31 +0200454 goto erret;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100455 }
456 vim_strncpy(from_name, si->sn_name, tail - si->sn_name);
457 add_pathsep(from_name);
458 STRCAT(from_name, tv.vval.v_string);
459 simplify_filename(from_name);
460
461 res = do_source(from_name, FALSE, DOSO_NONE, &sid);
462 vim_free(from_name);
463 }
464 else if (mch_isFullName(tv.vval.v_string))
465 {
466 // Absolute path: "/tmp/name.vim"
467 res = do_source(tv.vval.v_string, FALSE, DOSO_NONE, &sid);
468 }
469 else
470 {
471 size_t len = 7 + STRLEN(tv.vval.v_string) + 1;
472 char_u *from_name;
473
474 // Find file in "import" subdirs in 'runtimepath'.
475 from_name = alloc((int)len);
476 if (from_name == NULL)
477 {
478 clear_tv(&tv);
Bram Moolenaar1c991142020-07-04 13:15:31 +0200479 goto erret;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100480 }
481 vim_snprintf((char *)from_name, len, "import/%s", tv.vval.v_string);
482 res = source_in_path(p_rtp, from_name, DIP_NOAFTER, &sid);
483 vim_free(from_name);
484 }
485
486 if (res == FAIL || sid <= 0)
487 {
Bram Moolenaar451c2e32020-08-15 16:33:28 +0200488 semsg(_(e_could_not_import_str), tv.vval.v_string);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100489 clear_tv(&tv);
Bram Moolenaar1c991142020-07-04 13:15:31 +0200490 goto erret;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100491 }
492 clear_tv(&tv);
493
494 if (*arg_start == '*')
495 {
Bram Moolenaar0a842842021-02-27 22:41:19 +0100496 imported_T *imported;
497 char_u *as_name = ((char_u **)as_names.ga_data)[0];
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100498
Bram Moolenaar0a842842021-02-27 22:41:19 +0100499 // "import * as That"
Bram Moolenaara6294952020-12-27 13:39:50 +0100500 imported = find_imported(as_name, STRLEN(as_name), cctx);
501 if (imported != NULL && imported->imp_sid == sid)
502 {
503 if (imported->imp_flags & IMP_FLAGS_RELOAD)
504 // import already defined on a previous script load
505 imported->imp_flags &= ~IMP_FLAGS_RELOAD;
506 else
507 {
508 semsg(_(e_name_already_defined_str), as_name);
509 goto erret;
510 }
511 }
512
513 imported = new_imported(gap != NULL ? gap
514 : &SCRIPT_ITEM(import_sid)->sn_imports);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100515 if (imported == NULL)
Bram Moolenaar1c991142020-07-04 13:15:31 +0200516 goto erret;
517 imported->imp_name = as_name;
Bram Moolenaar0a842842021-02-27 22:41:19 +0100518 ((char_u **)as_names.ga_data)[0] = NULL;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100519 imported->imp_sid = sid;
Bram Moolenaara6294952020-12-27 13:39:50 +0100520 imported->imp_flags = IMP_FLAGS_STAR;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100521 }
522 else
523 {
Bram Moolenaar1c991142020-07-04 13:15:31 +0200524 int i;
525
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100526 arg = arg_start;
527 if (*arg == '{')
528 arg = skipwhite(arg + 1);
Bram Moolenaar1c991142020-07-04 13:15:31 +0200529 for (i = 0; i < names.ga_len; ++i)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100530 {
Bram Moolenaar1c991142020-07-04 13:15:31 +0200531 char_u *name = ((char_u **)names.ga_data)[i];
Bram Moolenaar0a842842021-02-27 22:41:19 +0100532 char_u *as_name = ((char_u **)as_names.ga_data)[i];
Bram Moolenaara6294952020-12-27 13:39:50 +0100533 size_t len = STRLEN(name);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100534 int idx;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100535 imported_T *imported;
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100536 ufunc_T *ufunc = NULL;
537 type_T *type;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100538
Bram Moolenaarcb4e80f2021-03-13 20:57:19 +0100539 idx = find_exported(sid, name, &ufunc, &type, cctx, TRUE);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100540
Bram Moolenaarf2d5c242020-02-23 21:25:54 +0100541 if (idx < 0 && ufunc == NULL)
Bram Moolenaar1c991142020-07-04 13:15:31 +0200542 goto erret;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100543
Bram Moolenaara6294952020-12-27 13:39:50 +0100544 // If already imported with the same propertis and the
545 // IMP_FLAGS_RELOAD set then we keep that entry. Otherwise create
546 // a new one (and give an error for an existing import).
547 imported = find_imported(name, len, cctx);
548 if (imported != NULL
549 && (imported->imp_flags & IMP_FLAGS_RELOAD)
550 && imported->imp_sid == sid
551 && (idx >= 0
552 ? (equal_type(imported->imp_type, type)
553 && imported->imp_var_vals_idx == idx)
554 : (equal_type(imported->imp_type, ufunc->uf_func_type)
555 && STRCMP(imported->imp_funcname,
556 ufunc->uf_name) == 0)))
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100557 {
Bram Moolenaara6294952020-12-27 13:39:50 +0100558 imported->imp_flags &= ~IMP_FLAGS_RELOAD;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100559 }
560 else
Bram Moolenaar40f4f7a2020-07-23 22:41:43 +0200561 {
Bram Moolenaar057e84a2021-02-28 16:55:11 +0100562 if (check_defined(name, len, cctx, FALSE) == FAIL)
Bram Moolenaara6294952020-12-27 13:39:50 +0100563 goto erret;
564
565 imported = new_imported(gap != NULL ? gap
566 : &SCRIPT_ITEM(import_sid)->sn_imports);
567 if (imported == NULL)
568 goto erret;
569
Bram Moolenaar0a842842021-02-27 22:41:19 +0100570 if (as_name == NULL)
571 {
572 imported->imp_name = name;
573 ((char_u **)names.ga_data)[i] = NULL;
Bram Moolenaar057e84a2021-02-28 16:55:11 +0100574 }
Bram Moolenaar0a842842021-02-27 22:41:19 +0100575 else
576 {
577 // "import This as That ..."
578 imported->imp_name = as_name;
579 ((char_u **)as_names.ga_data)[i] = NULL;
580 }
Bram Moolenaara6294952020-12-27 13:39:50 +0100581 imported->imp_sid = sid;
582 if (idx >= 0)
583 {
584 imported->imp_type = type;
585 imported->imp_var_vals_idx = idx;
586 }
587 else
588 {
589 imported->imp_type = ufunc->uf_func_type;
590 imported->imp_funcname = ufunc->uf_name;
591 }
Bram Moolenaar40f4f7a2020-07-23 22:41:43 +0200592 }
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100593 }
594 }
Bram Moolenaar1c991142020-07-04 13:15:31 +0200595erret:
596 ga_clear_strings(&names);
Bram Moolenaar0a842842021-02-27 22:41:19 +0100597 ga_clear_strings(&as_names);
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100598 return cmd_end;
599}
600
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200601/*
602 * Declare a script-local variable without init: "let var: type".
603 * "const" is an error since the value is missing.
604 * Returns a pointer to after the type.
605 */
606 char_u *
607vim9_declare_scriptvar(exarg_T *eap, char_u *arg)
608{
609 char_u *p;
610 char_u *name;
611 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
612 type_T *type;
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200613 typval_T init_tv;
614
Bram Moolenaar30fd8202020-09-26 15:09:30 +0200615 if (eap->cmdidx == CMD_final || eap->cmdidx == CMD_const)
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200616 {
Bram Moolenaar30fd8202020-09-26 15:09:30 +0200617 if (eap->cmdidx == CMD_final)
618 emsg(_(e_final_requires_a_value));
619 else
620 emsg(_(e_const_requires_a_value));
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200621 return arg + STRLEN(arg);
622 }
623
624 // Check for valid starting character.
625 if (!eval_isnamec1(*arg))
626 {
627 semsg(_(e_invarg2), arg);
628 return arg + STRLEN(arg);
629 }
630
Bram Moolenaar984dddb2020-06-14 12:50:24 +0200631 for (p = arg + 1; *p != NUL && eval_isnamec(*p); MB_PTR_ADV(p))
Bram Moolenaar3b74b6b2020-06-19 19:01:43 +0200632 if (*p == ':' && (VIM_ISWHITE(p[1]) || p != arg + 1))
Bram Moolenaar984dddb2020-06-14 12:50:24 +0200633 break;
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200634
635 if (*p != ':')
636 {
Bram Moolenaarbc4c5052020-08-13 22:47:35 +0200637 emsg(_(e_type_or_initialization_required));
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200638 return arg + STRLEN(arg);
639 }
Bram Moolenaar984dddb2020-06-14 12:50:24 +0200640 if (!VIM_ISWHITE(p[1]))
641 {
Bram Moolenaarc3fc75d2021-02-07 15:28:09 +0100642 semsg(_(e_white_space_required_after_str_str), ":", p);
Bram Moolenaar984dddb2020-06-14 12:50:24 +0200643 return arg + STRLEN(arg);
644 }
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200645 name = vim_strnsave(arg, p - arg);
646
647 // parse type
648 p = skipwhite(p + 1);
Bram Moolenaar9e68c322020-12-25 12:38:04 +0100649 type = parse_type(&p, &si->sn_type_list, TRUE);
650 if (type == NULL)
Bram Moolenaarf3decc52020-06-13 19:56:38 +0200651 {
652 vim_free(name);
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200653 return p;
Bram Moolenaarf3decc52020-06-13 19:56:38 +0200654 }
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200655
656 // Create the variable with 0/NULL value.
657 CLEAR_FIELD(init_tv);
Bram Moolenaarf0afd9e2020-09-13 18:57:47 +0200658 if (type->tt_type == VAR_ANY)
659 // A variable of type "any" is not possible, just use zero instead
660 init_tv.v_type = VAR_NUMBER;
661 else
662 init_tv.v_type = type->tt_type;
Bram Moolenaarf785aa12021-02-11 21:19:34 +0100663 set_var_const(name, type, &init_tv, FALSE, 0, 0);
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200664
665 vim_free(name);
666 return p;
667}
668
Bram Moolenaar34db91f2020-06-13 19:00:10 +0200669/*
Bram Moolenaar39ca4122020-10-20 14:25:07 +0200670 * Vim9 part of adding a script variable: add it to sn_all_vars (lookup by name
671 * with a hashtable) and sn_var_vals (lookup by index).
Bram Moolenaar07a65d22020-12-26 20:09:15 +0100672 * When "create" is TRUE this is a new variable, otherwise find and update an
673 * existing variable.
Bram Moolenaar08251752021-01-11 21:20:18 +0100674 * "flags" can have ASSIGN_FINAL or ASSIGN_CONST.
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100675 * When "*type" is NULL use "tv" for the type and update "*type".
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200676 */
677 void
Bram Moolenaar08251752021-01-11 21:20:18 +0100678update_vim9_script_var(
679 int create,
680 dictitem_T *di,
681 int flags,
682 typval_T *tv,
683 type_T **type)
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200684{
Bram Moolenaar07a65d22020-12-26 20:09:15 +0100685 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
686 hashitem_T *hi;
687 svar_T *sv;
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200688
Bram Moolenaar07a65d22020-12-26 20:09:15 +0100689 if (create)
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200690 {
Bram Moolenaar07a65d22020-12-26 20:09:15 +0100691 sallvar_T *newsav;
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200692
Bram Moolenaar07a65d22020-12-26 20:09:15 +0100693 // Store a pointer to the typval_T, so that it can be found by index
694 // instead of using a hastab lookup.
695 if (ga_grow(&si->sn_var_vals, 1) == FAIL)
696 return;
697
698 sv = ((svar_T *)si->sn_var_vals.ga_data) + si->sn_var_vals.ga_len;
699 newsav = (sallvar_T *)alloc_clear(
700 sizeof(sallvar_T) + STRLEN(di->di_key));
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200701 if (newsav == NULL)
702 return;
703
704 sv->sv_tv = &di->di_tv;
Bram Moolenaar08251752021-01-11 21:20:18 +0100705 sv->sv_const = (flags & ASSIGN_FINAL) ? ASSIGN_FINAL
706 : (flags & ASSIGN_CONST) ? ASSIGN_CONST : 0;
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200707 sv->sv_export = is_export;
708 newsav->sav_var_vals_idx = si->sn_var_vals.ga_len;
709 ++si->sn_var_vals.ga_len;
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200710 STRCPY(&newsav->sav_key, di->di_key);
711 sv->sv_name = newsav->sav_key;
712 newsav->sav_di = di;
713 newsav->sav_block_id = si->sn_current_block_id;
714
715 hi = hash_find(&si->sn_all_vars.dv_hashtab, newsav->sav_key);
716 if (!HASHITEM_EMPTY(hi))
717 {
718 sallvar_T *sav = HI2SAV(hi);
719
720 // variable with this name exists in another block
721 while (sav->sav_next != NULL)
722 sav = sav->sav_next;
723 sav->sav_next = newsav;
724 }
725 else
726 // new variable name
727 hash_add(&si->sn_all_vars.dv_hashtab, newsav->sav_key);
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200728 }
Bram Moolenaar07a65d22020-12-26 20:09:15 +0100729 else
730 {
731 sv = find_typval_in_script(&di->di_tv);
732 }
733 if (sv != NULL)
734 {
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100735 if (*type == NULL)
736 *type = typval2type(tv, &si->sn_type_list);
737 sv->sv_type = *type;
Bram Moolenaar07a65d22020-12-26 20:09:15 +0100738 }
739
740 // let ex_export() know the export worked.
741 is_export = FALSE;
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200742}
743
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200744/*
745 * Hide a script variable when leaving a block.
746 * "idx" is de index in sn_var_vals.
Bram Moolenaar39ca4122020-10-20 14:25:07 +0200747 * When "func_defined" is non-zero then a function was defined in this block,
748 * the variable may be accessed by it. Otherwise the variable can be cleared.
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200749 */
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200750 void
Bram Moolenaar39ca4122020-10-20 14:25:07 +0200751hide_script_var(scriptitem_T *si, int idx, int func_defined)
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200752{
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200753 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200754 hashtab_T *script_ht = get_script_local_ht();
755 hashtab_T *all_ht = &si->sn_all_vars.dv_hashtab;
756 hashitem_T *script_hi;
757 hashitem_T *all_hi;
758
759 // Remove a variable declared inside the block, if it still exists.
Bram Moolenaar39ca4122020-10-20 14:25:07 +0200760 // If it was added in a nested block it will already have been removed.
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200761 // The typval is moved into the sallvar_T.
762 script_hi = hash_find(script_ht, sv->sv_name);
763 all_hi = hash_find(all_ht, sv->sv_name);
764 if (!HASHITEM_EMPTY(script_hi) && !HASHITEM_EMPTY(all_hi))
765 {
766 dictitem_T *di = HI2DI(script_hi);
767 sallvar_T *sav = HI2SAV(all_hi);
Bram Moolenaar39ca4122020-10-20 14:25:07 +0200768 sallvar_T *sav_prev = NULL;
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200769
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200770 // There can be multiple entries with the same name in different
771 // blocks, find the right one.
772 while (sav != NULL && sav->sav_var_vals_idx != idx)
Bram Moolenaar39ca4122020-10-20 14:25:07 +0200773 {
774 sav_prev = sav;
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200775 sav = sav->sav_next;
Bram Moolenaar39ca4122020-10-20 14:25:07 +0200776 }
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200777 if (sav != NULL)
778 {
Bram Moolenaar39ca4122020-10-20 14:25:07 +0200779 if (func_defined)
780 {
781 // move the typval from the dictitem to the sallvar
782 sav->sav_tv = di->di_tv;
783 di->di_tv.v_type = VAR_UNKNOWN;
784 sav->sav_flags = di->di_flags;
785 sav->sav_di = NULL;
786 sv->sv_tv = &sav->sav_tv;
787 }
788 else
789 {
790 if (sav_prev == NULL)
791 hash_remove(all_ht, all_hi);
792 else
793 sav_prev->sav_next = sav->sav_next;
794 sv->sv_name = NULL;
795 vim_free(sav);
796 }
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200797 delete_var(script_ht, script_hi);
Bram Moolenaarfbbcd002020-10-15 12:46:44 +0200798 }
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200799 }
800}
801
802/*
803 * Free the script variables from "sn_all_vars".
804 */
805 void
806free_all_script_vars(scriptitem_T *si)
807{
808 int todo;
809 hashtab_T *ht = &si->sn_all_vars.dv_hashtab;
810 hashitem_T *hi;
811 sallvar_T *sav;
812 sallvar_T *sav_next;
813
814 hash_lock(ht);
815 todo = (int)ht->ht_used;
816 for (hi = ht->ht_array; todo > 0; ++hi)
817 {
818 if (!HASHITEM_EMPTY(hi))
819 {
820 --todo;
821
822 // Free the variable. Don't remove it from the hashtab, ht_array
823 // might change then. hash_clear() takes care of it later.
824 sav = HI2SAV(hi);
825 while (sav != NULL)
826 {
827 sav_next = sav->sav_next;
828 if (sav->sav_di == NULL)
829 clear_tv(&sav->sav_tv);
830 vim_free(sav);
831 sav = sav_next;
832 }
833 }
834 }
835 hash_clear(ht);
836 hash_init(ht);
837
838 ga_clear(&si->sn_var_vals);
Bram Moolenaar2b327002020-12-26 15:39:31 +0100839
840 // existing commands using script variable indexes are no longer valid
841 si->sn_script_seq = current_sctx.sc_seq;
Bram Moolenaar8d739de2020-10-14 19:39:19 +0200842}
843
844/*
Bram Moolenaar10c65862020-10-08 21:16:42 +0200845 * Find the script-local variable that links to "dest".
846 * Returns NULL if not found.
Bram Moolenaar34db91f2020-06-13 19:00:10 +0200847 */
Bram Moolenaar10c65862020-10-08 21:16:42 +0200848 svar_T *
849find_typval_in_script(typval_T *dest)
Bram Moolenaar34db91f2020-06-13 19:00:10 +0200850{
851 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
852 int idx;
853
Bram Moolenaar81e17fb2020-08-21 21:55:43 +0200854 if (si->sn_version != SCRIPT_VERSION_VIM9)
855 // legacy script doesn't store variable types
Bram Moolenaar10c65862020-10-08 21:16:42 +0200856 return NULL;
Bram Moolenaar81e17fb2020-08-21 21:55:43 +0200857
Bram Moolenaar34db91f2020-06-13 19:00:10 +0200858 // Find the svar_T in sn_var_vals.
859 for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx)
860 {
861 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
862
Bram Moolenaarc0913d02020-12-05 14:44:37 +0100863 // If "sv_name" is NULL the variable was hidden when leaving a block,
864 // don't check "sv_tv" then, it might be used for another variable now.
865 if (sv->sv_name != NULL && sv->sv_tv == dest)
Bram Moolenaar10c65862020-10-08 21:16:42 +0200866 return sv;
Bram Moolenaar34db91f2020-06-13 19:00:10 +0200867 }
Bram Moolenaarf785aa12021-02-11 21:19:34 +0100868 iemsg("find_typval_in_script(): not found");
Bram Moolenaar10c65862020-10-08 21:16:42 +0200869 return NULL;
870}
871
872/*
873 * Check if the type of script variable "dest" allows assigning "value".
874 * If needed convert "value" to a bool.
875 */
876 int
Bram Moolenaarf785aa12021-02-11 21:19:34 +0100877check_script_var_type(
878 typval_T *dest,
879 typval_T *value,
880 char_u *name,
881 where_T where)
Bram Moolenaar10c65862020-10-08 21:16:42 +0200882{
883 svar_T *sv = find_typval_in_script(dest);
884 int ret;
885
886 if (sv != NULL)
887 {
Bram Moolenaar08251752021-01-11 21:20:18 +0100888 if (sv->sv_const != 0)
Bram Moolenaar10c65862020-10-08 21:16:42 +0200889 {
890 semsg(_(e_readonlyvar), name);
891 return FAIL;
892 }
Bram Moolenaarf785aa12021-02-11 21:19:34 +0100893 ret = check_typval_type(sv->sv_type, value, where);
Bram Moolenaar10c65862020-10-08 21:16:42 +0200894 if (ret == OK && need_convert_to_bool(sv->sv_type, value))
895 {
896 int val = tv2bool(value);
897
898 clear_tv(value);
899 value->v_type = VAR_BOOL;
900 value->v_lock = 0;
901 value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE;
902 }
903 return ret;
904 }
905
Bram Moolenaarc785b9a2020-06-19 18:34:15 +0200906 return OK; // not really
Bram Moolenaar34db91f2020-06-13 19:00:10 +0200907}
Bram Moolenaarc82a5b52020-06-13 18:09:19 +0200908
Bram Moolenaar8a7d6542020-01-26 15:56:19 +0100909#endif // FEAT_EVAL