mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 06:58:35 +00:00
feat(lua): print source locations of lua callbacks (#19597)
Co-authored-by: ii14 <ii14@users.noreply.github.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user