From 3da3cfc864e89a2dca6917183915683373c85af8 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 9 Jun 2022 15:18:56 +0200 Subject: feat(autocmds): retrieve lua callback (#18642) add a new `callback` field to `nvim_get_autocmds` --- src/nvim/eval/typval.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 2c76741891..97726da5f4 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1205,6 +1205,30 @@ void callback_copy(Callback *dest, Callback *src) } } +/// Generate a string description of a callback +char *callback_to_string(Callback *cb) +{ + size_t msglen = 100; + char *msg = (char *)xmallocz(msglen); + + switch (cb->type) { + case kCallbackLua: + snprintf(msg, msglen, "", cb->data.luaref); + break; + case kCallbackFuncref: + // TODO(tjdevries): Is this enough space for this? + snprintf(msg, msglen, "", cb->data.funcref); + break; + case kCallbackPartial: + snprintf(msg, msglen, "", cb->data.partial->pt_name); + break; + default: + snprintf(msg, msglen, "%s", ""); + break; + } + return msg; +} + /// Remove watcher from a dictionary /// /// @param dict Dictionary to remove watcher from. -- cgit