From dcb53be4418fe263a71c7738315241031df6c986 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 9 Dec 2021 14:23:43 +0000 Subject: patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others Problem: Vim9: cannot use a lambda for 'opfunc' and others. Solution: Convert the lambda to a string. --- src/vim9execute.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/vim9execute.c') diff --git a/src/vim9execute.c b/src/vim9execute.c index f805dc0f1..874e57c58 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -2336,10 +2336,14 @@ exec_instructions(ectx_T *ectx) // store option case ISN_STOREOPT: + case ISN_STOREFUNCOPT: { + char_u *opt_name = iptr->isn_arg.storeopt.so_name; + int opt_flags = iptr->isn_arg.storeopt.so_flags; long n = 0; char_u *s = NULL; char *msg; + callback_T cb = {NULL, NULL, 0}; --ectx->ec_stack.ga_len; tv = STACK_TV_BOT(0); @@ -2349,11 +2353,22 @@ exec_instructions(ectx_T *ectx) if (s == NULL) s = (char_u *)""; } + else if (iptr->isn_type == ISN_STOREFUNCOPT) + { + SOURCING_LNUM = iptr->isn_lnum; + cb = get_callback(tv); + if (cb.cb_name == NULL || *cb.cb_name == NUL) + { + clear_tv(tv); + free_callback(&cb); + goto on_error; + } + s = cb.cb_name; + } else // must be VAR_NUMBER, CHECKTYPE makes sure n = tv->vval.v_number; - msg = set_option_value(iptr->isn_arg.storeopt.so_name, - n, s, iptr->isn_arg.storeopt.so_flags); + msg = set_option_value(opt_name, n, s, opt_flags); clear_tv(tv); if (msg != NULL) { @@ -2361,6 +2376,8 @@ exec_instructions(ectx_T *ectx) emsg(_(msg)); goto on_error; } + if (cb.cb_name != NULL) + free_callback(&cb); } break; @@ -5335,7 +5352,9 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc) } break; case ISN_STOREOPT: - smsg("%s%4d STOREOPT &%s", pfx, current, + case ISN_STOREFUNCOPT: + smsg("%s%4d %s &%s", pfx, current, + iptr->isn_type == ISN_STOREOPT ? "STOREOPT" : "STOREFUNCOPT", iptr->isn_arg.storeopt.so_name); break; case ISN_STOREENV: -- cgit v1.2.1