aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vis-cmds.c15
-rw-r--r--vis-lua.c13
-rw-r--r--vis-lua.h6
3 files changed, 33 insertions, 1 deletions
diff --git a/vis-cmds.c b/vis-cmds.c
index 6be5fd8..8ec45c8 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
@@ -1,6 +1,7 @@
/* this file is included from sam.c */
#include <termkey.h>
+#include "vis-lua.h"
#ifndef VIS_OPEN
#define VIS_OPEN "vis-open"
@@ -659,6 +660,20 @@ 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);
+ }
+ free (copy);
+ }
+
text_save(txt, NULL);
return true;
}
diff --git a/vis-lua.c b/vis-lua.c
index 9c17849..50d0596 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -17,6 +17,8 @@
#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; }
void vis_lua_init(Vis *vis) { }
void vis_lua_start(Vis *vis) { }
void vis_lua_quit(Vis *vis) { }
@@ -1033,7 +1035,7 @@ static bool vis_lua_path_strip(Vis *vis) {
return true;
}
-static bool vis_lua_path_add(Vis *vis, const char *path) {
+bool vis_lua_path_add(Vis *vis, const char *path) {
if (!path)
return false;
lua_State *L = vis->lua;
@@ -1049,6 +1051,15 @@ static bool vis_lua_path_add(Vis *vis, const char *path) {
return true;
}
+const char *vis_lua_paths_get(Vis *vis) {
+ lua_State *L = vis->lua;
+ if (!L)
+ return NULL;
+ lua_getglobal(L, "package");
+ lua_getfield(L, -1, "path");
+ return lua_tostring(L, -1);
+}
+
void vis_lua_init(Vis *vis) {
lua_State *L = luaL_newstate();
if (!L)
diff --git a/vis-lua.h b/vis-lua.h
index b05f6fb..2b06e0a 100644
--- a/vis-lua.h
+++ b/vis-lua.h
@@ -11,6 +11,12 @@ typedef struct lua_State lua_State;
#include "vis.h"
+/* 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*);
+
+/* various event handlers, triggered by the vis core */
void vis_lua_init(Vis*);
void vis_lua_start(Vis*);
void vis_lua_quit(Vis*);