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.
3a97bb3f0f

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
This commit is contained in:
Jan Edmund Lazo
2021-06-22 08:50:18 -04:00
parent 24e0c16fd6
commit d5329c0331
4 changed files with 20 additions and 12 deletions

View File

@@ -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.