diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-08-07 16:01:34 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-08-07 16:01:34 -0600 |
commit | a5f27a311fb28797a72b8aa16ec7122c5a1b15e4 (patch) | |
tree | 3732f7339e29431f31310aef6ffc802cf4f6255d /src/nvim/lua/executor.c | |
parent | 6c909fedc924d9f4257aa204b0168c6177cc5d28 (diff) | |
parent | 629169462a82f0fbb7a8911a4554894537d6776c (diff) | |
download | rneovim-a5f27a311fb28797a72b8aa16ec7122c5a1b15e4.tar.gz rneovim-a5f27a311fb28797a72b8aa16ec7122c5a1b15e4.tar.bz2 rneovim-a5f27a311fb28797a72b8aa16ec7122c5a1b15e4.zip |
Merge branch 'master' of https://github.com/neovim/neovim into rahm
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 17157ccdc2..661dbfc4c2 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -21,7 +21,6 @@ #include "nvim/event/loop.h" #include "nvim/event/time.h" #include "nvim/ex_cmds2.h" -#include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/extmark.h" #include "nvim/func_attr.h" @@ -40,6 +39,7 @@ #include "nvim/profile.h" #include "nvim/screen.h" #include "nvim/undo.h" +#include "nvim/usercmd.h" #include "nvim/version.h" #include "nvim/vim.h" #include "nvim/window.h" @@ -2076,3 +2076,34 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview) return retv; } + +/// String representation of a Lua function reference +/// +/// @return Allocated string +char *nlua_funcref_str(LuaRef ref) +{ + lua_State *const lstate = global_lstate; + StringBuilder str = KV_INITIAL_VALUE; + kv_resize(str, 16); + + if (!lua_checkstack(lstate, 1)) { + goto plain; + } + nlua_pushref(lstate, ref); + if (!lua_isfunction(lstate, -1)) { + lua_pop(lstate, 1); + goto plain; + } + + lua_Debug ar; + if (lua_getinfo(lstate, ">S", &ar) && *ar.source == '@' && ar.linedefined >= 0) { + char *src = home_replace_save(NULL, ar.source + 1); + kv_printf(str, "<Lua %d: %s:%d>", ref, src, ar.linedefined); + xfree(src); + return str.items; + } + +plain: + kv_printf(str, "<Lua %d>", ref); + return str.items; +} |