aboutsummaryrefslogtreecommitdiff
path: root/vis-lua.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-12-07 16:49:29 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-12-07 20:11:32 +0100
commit3570869c9ae2c4df14b15423789919e514322916 (patch)
tree6b990c9ec59fbdc7abce89c1307d22e66d0fd88a /vis-lua.c
parent098504f67aea8a862840d58c69e8f6360eef3073 (diff)
downloadvis-3570869c9ae2c4df14b15423789919e514322916.tar.gz
vis-3570869c9ae2c4df14b15423789919e514322916.tar.xz
Move all lua related files to lua/ subfolder
Also remove the lexers sub directory from the Lua search path. As a result we attempt to open fewer files during startup: $ strace -e open -o log ./vis +q config.h && wc -l log In order to avoid having to modifiy all lexers which `require('lexer')` we instead place a symlink in the top level directory. $ ./configure --disable-lua $ rm -rf lua Should result in a source tree with most lua specifc functionality removed.
Diffstat (limited to 'vis-lua.c')
-rw-r--r--vis-lua.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/vis-lua.c b/vis-lua.c
index b88a1d1..f3b0114 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -1804,10 +1804,8 @@ bool vis_lua_path_add(Vis *vis, const char *path) {
lua_getglobal(L, "package");
lua_pushstring(L, path);
lua_pushstring(L, "/?.lua;");
- lua_pushstring(L, path);
- lua_pushstring(L, "/lexers/?.lua;");
- lua_getfield(L, -5, "path");
- lua_concat(L, 5);
+ lua_getfield(L, -3, "path");
+ lua_concat(L, 3);
lua_setfield(L, -2, "path");
lua_pop(L, 1); /* package */
return true;
@@ -1888,7 +1886,17 @@ void vis_lua_init(Vis *vis) {
ssize_t len = readlink("/proc/self/exe", path, sizeof(path)-1);
if (len > 0) {
path[len] = '\0';
- vis_lua_path_add(vis, dirname(path));
+ /* some idotic dirname(3) implementations return pointers to statically
+ * allocated memory, hence we use memmove to copy it back */
+ char *dir = dirname(path);
+ if (dir) {
+ size_t len = strlen(dir)+1;
+ if (len < sizeof(path) - sizeof("/lua")) {
+ memmove(path, dir, len);
+ strcat(path, "/lua");
+ vis_lua_path_add(vis, path);
+ }
+ }
}
vis_lua_path_add(vis, getenv("VIS_PATH"));