diff options
author | ii14 <59243201+ii14@users.noreply.github.com> | 2022-08-03 14:41:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-03 13:41:17 +0100 |
commit | 3df8d9b8c56a7f0af0f7590b11831bd96ead92f1 (patch) | |
tree | 23703fdf6aa7b32fe317e1cb5cbc6ee62e8d58c7 /src/nvim/lua/executor.c | |
parent | c57e133e50b9f3ccd9a3d73f4e7e3e7281797000 (diff) | |
download | rneovim-3df8d9b8c56a7f0af0f7590b11831bd96ead92f1.tar.gz rneovim-3df8d9b8c56a7f0af0f7590b11831bd96ead92f1.tar.bz2 rneovim-3df8d9b8c56a7f0af0f7590b11831bd96ead92f1.zip |
feat(lua): print source locations of lua callbacks (#19597)
Co-authored-by: ii14 <ii14@users.noreply.github.com>
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 17157ccdc2..197a209e97 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -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; +} |