From d5329c0331a4e899ea88277b745df8d1bf3a99fa Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 22 Jun 2021 08:50:18 -0400 Subject: vim-patch:8.1.1437: code to handle callbacks is duplicated Problem: Code to handle callbacks is duplicated. Solution: Add callback_T and functions to deal with it. https://github.com/vim/vim/commit/3a97bb3f0f8bd118ae23f1c97e55d84ff42eef20 Port Vim's put_callback() as callback_put() because Neovim's naming convention is {type}_{action}, not {action}_{type}. Renaming put_callback type as PutCallback. https://neovim.io/develop/style-guide.xml#Type_Names --- src/nvim/eval/typval.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 61de83fc21..4118ec407c 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1164,6 +1164,21 @@ void callback_free(Callback *callback) callback->type = kCallbackNone; } +/// Copy a callback into a typval_T. +void callback_put(Callback *cb, typval_T *tv) + FUNC_ATTR_NONNULL_ALL +{ + if (cb->type == kCallbackPartial) { + tv->v_type = VAR_PARTIAL; + tv->vval.v_partial = cb->data.partial; + cb->data.partial->pt_refcount++; + } else if (cb->type == kCallbackFuncref) { + tv->v_type = VAR_FUNC; + tv->vval.v_string = vim_strsave(cb->data.funcref); + func_ref(cb->data.funcref); + } +} + /// Remove watcher from a dictionary /// /// @param dict Dictionary to remove watcher from. -- cgit