From 47e82949164c23973dbad72d3982d9aef557d118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 5 Nov 2016 16:28:59 +0100 Subject: vis: display Lua package.cpath in :help output These paths are used to load the Lua LPeg module (lpeg.so) and are thus helpful when diagnosing setup problems in case syntax highlighting does not work. --- vis-cmds.c | 27 ++++++++++++++++----------- vis-lua.c | 14 ++++++++++---- vis-lua.h | 6 ++++-- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/vis-cmds.c b/vis-cmds.c index 87ebd67..ab4a4d2 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -653,18 +653,23 @@ static bool cmd_help(Vis *vis, Win *win, Command *cmd, const char *argv[], Curso "(prefix with C-, S-, and M- for Ctrl, Shift and Alt respectively)\n\n"); print_symbolic_keys(vis, txt); - const char *paths = vis_lua_paths_get(vis); - if (paths) { - char *copy = strdup(paths); - text_appendf(txt, "\n Lua paths used to load runtime files " - "(? will be replaced by filename):\n\n"); - for (char *elem = copy, *next; elem; elem = next) { - if ((next = strstr(elem, ";"))) - *next++ = '\0'; - if (*elem) - text_appendf(txt, " %s\n", elem); + char *paths[] = { NULL, NULL }; + char *paths_description[] = { + "Lua paths used to load runtime files (? will be replaced by filename):", + "Lua paths used to load C libraries (? will be replaced by filename):", + }; + + if (vis_lua_paths_get(vis, &paths[0], &paths[1])) { + for (size_t i = 0; i < LENGTH(paths); i++) { + text_appendf(txt, "\n %s\n\n", paths_description[i]); + for (char *elem = paths[i], *next; elem; elem = next) { + if ((next = strstr(elem, ";"))) + *next++ = '\0'; + if (*elem) + text_appendf(txt, " %s\n", elem); + } + free(paths[i]); } - free (copy); } text_save(txt, NULL); diff --git a/vis-lua.c b/vis-lua.c index 7f045fa..8431111 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -123,7 +123,7 @@ static void window_status_update(Vis *vis, Win *win) { #if !CONFIG_LUA bool vis_lua_path_add(Vis *vis, const char *path) { return true; } -const char *vis_lua_paths_get(Vis *vis) { return NULL; } +bool vis_lua_paths_get(Vis *vis, const char **lpath, const char **cpath) { return false; } void vis_lua_init(Vis *vis) { } void vis_lua_start(Vis *vis) { } void vis_lua_quit(Vis *vis) { } @@ -1343,13 +1343,19 @@ bool vis_lua_path_add(Vis *vis, const char *path) { return true; } -const char *vis_lua_paths_get(Vis *vis) { +bool vis_lua_paths_get(Vis *vis, char **lpath, char **cpath) { lua_State *L = vis->lua; if (!L) - return NULL; + return false; + const char *s; lua_getglobal(L, "package"); lua_getfield(L, -1, "path"); - return lua_tostring(L, -1); + s = lua_tostring(L, -1); + *lpath = s ? strdup(s) : NULL; + lua_getfield(L, -2, "cpath"); + s = lua_tostring(L, -1); + *cpath = s ? strdup(s) : NULL; + return true; } static bool package_exist(Vis *vis, lua_State *L, const char *name) { diff --git a/vis-lua.h b/vis-lua.h index 644ce73..9732735 100644 --- a/vis-lua.h +++ b/vis-lua.h @@ -13,8 +13,10 @@ typedef struct lua_State lua_State; /* add a directory to consider when loading lua files */ bool vis_lua_path_add(Vis*, const char *path); -/* get semi colon separated list of paths to load lua files */ -const char *vis_lua_paths_get(Vis*); +/* get semicolon separated list of paths to load lua files + * (*lpath = package.path) and Lua C modules (*cpath = package.cpath) + * both these pointers need to be free(3)-ed by the caller */ +bool vis_lua_paths_get(Vis*, char **lpath, char **cpath); /* various event handlers, triggered by the vis core */ void vis_lua_init(Vis*); -- cgit v1.2.3