From 3570869c9ae2c4df14b15423789919e514322916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 7 Dec 2016 16:49:29 +0100 Subject: 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. --- vis-lua.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'vis-lua.c') 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")); -- cgit v1.2.3