Add an option to add a path to $LUA_PATH

The same effect could be achieved by modifying $LUA_PATH or with symlinks, but
having a special option to do this seems easier.

Note that the man page translations were generated via Google translate. I'm
looking forward to people submitting correct translations...

Inspired-by: https://github.com/awesomeWM/awesome/pull/485
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-07-24 14:57:14 +02:00
parent f95449a4bb
commit 24bb38969d
9 changed files with 63 additions and 22 deletions

View File

@ -429,6 +429,7 @@ exit_help(int exit_code)
-h, --help show help\n\ -h, --help show help\n\
-v, --version show version\n\ -v, --version show version\n\
-c, --config FILE configuration file to use\n\ -c, --config FILE configuration file to use\n\
--search DIR add a directory to the library search path\n\
-k, --check check configuration file syntax\n\ -k, --check check configuration file syntax\n\
-a, --no-argb disable client transparency support\n\ -a, --no-argb disable client transparency support\n\
-r, --replace replace an existing window manager\n"); -r, --replace replace an existing window manager\n");
@ -444,6 +445,7 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *confpath = NULL; char *confpath = NULL;
string_array_t searchpath;
int xfd, i, opt; int xfd, i, opt;
ssize_t cmdlen = 1; ssize_t cmdlen = 1;
xdgHandle xdg; xdgHandle xdg;
@ -457,6 +459,7 @@ main(int argc, char **argv)
{ "version", 0, NULL, 'v' }, { "version", 0, NULL, 'v' },
{ "config", 1, NULL, 'c' }, { "config", 1, NULL, 'c' },
{ "check", 0, NULL, 'k' }, { "check", 0, NULL, 'k' },
{ "search", 1, NULL, 's' },
{ "no-argb", 0, NULL, 'a' }, { "no-argb", 0, NULL, 'a' },
{ "replace", 0, NULL, 'r' }, { "replace", 0, NULL, 'r' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
@ -471,6 +474,7 @@ main(int argc, char **argv)
globalconf.keygrabber = LUA_REFNIL; globalconf.keygrabber = LUA_REFNIL;
globalconf.mousegrabber = LUA_REFNIL; globalconf.mousegrabber = LUA_REFNIL;
buffer_init(&globalconf.startup_errors); buffer_init(&globalconf.startup_errors);
string_array_init(&searchpath);
/* save argv */ /* save argv */
for(i = 0; i < argc; i++) for(i = 0; i < argc; i++)
@ -488,12 +492,6 @@ main(int argc, char **argv)
/* Text won't be printed correctly otherwise */ /* Text won't be printed correctly otherwise */
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
/* Get XDG basedir data */
xdgInitHandle(&xdg);
/* init lua */
luaA_init(&xdg);
/* check args */ /* check args */
while((opt = getopt_long(argc, argv, "vhkc:ar", while((opt = getopt_long(argc, argv, "vhkc:ar",
long_options, NULL)) != -1) long_options, NULL)) != -1)
@ -514,6 +512,12 @@ main(int argc, char **argv)
else else
fatal("-c option requires a file name"); fatal("-c option requires a file name");
break; break;
case 's':
if(a_strlen(optarg))
string_array_append(&searchpath, a_strdup(optarg));
else
fatal("-s option requires a directory name");
break;
case 'a': case 'a':
no_argb = true; no_argb = true;
break; break;
@ -522,6 +526,13 @@ main(int argc, char **argv)
break; break;
} }
/* Get XDG basedir data */
xdgInitHandle(&xdg);
/* init lua */
luaA_init(&xdg, &searchpath);
string_array_wipe(&searchpath);
if (run_test) if (run_test)
{ {
if(!luaA_parserc(&xdg, confpath, false)) if(!luaA_parserc(&xdg, confpath, false))

29
luaa.c
View File

@ -590,7 +590,7 @@ setup_awesome_signals(lua_State *L)
* \param xdg An xdg handle to use to get XDG basedir. * \param xdg An xdg handle to use to get XDG basedir.
*/ */
void void
luaA_init(xdgHandle* xdg) luaA_init(xdgHandle* xdg, string_array_t *searchpath)
{ {
lua_State *L; lua_State *L;
static const struct luaL_Reg awesome_lib[] = static const struct luaL_Reg awesome_lib[] =
@ -681,6 +681,19 @@ luaA_init(xdgHandle* xdg)
/* Export keys */ /* Export keys */
key_class_setup(L); key_class_setup(L);
/* add XDG_CONFIG_DIR as include path */
const char * const *xdgconfigdirs = xdgSearchableConfigDirectories(xdg);
for(; *xdgconfigdirs; xdgconfigdirs++)
{
/* Append /awesome to *xdgconfigdirs */
const char *suffix = "/awesome";
size_t len = a_strlen(*xdgconfigdirs) + a_strlen(suffix) + 1;
char *entry = p_new(char, len);
a_strcat(entry, len, *xdgconfigdirs);
a_strcat(entry, len, suffix);
string_array_append(searchpath, entry);
}
/* add Lua search paths */ /* add Lua search paths */
lua_getglobal(L, "package"); lua_getglobal(L, "package");
if (LUA_TTABLE != lua_type(L, 1)) if (LUA_TTABLE != lua_type(L, 1))
@ -696,19 +709,17 @@ luaA_init(xdgHandle* xdg)
return; return;
} }
/* add XDG_CONFIG_DIR as include path */ foreach(entry, *searchpath)
const char * const *xdgconfigdirs = xdgSearchableConfigDirectories(xdg);
for(; *xdgconfigdirs; xdgconfigdirs++)
{ {
size_t len = a_strlen(*xdgconfigdirs); size_t len = a_strlen(*entry);
lua_pushliteral(L, ";"); lua_pushliteral(L, ";");
lua_pushlstring(L, *xdgconfigdirs, len); lua_pushlstring(L, *entry, len);
lua_pushliteral(L, "/awesome/?.lua"); lua_pushliteral(L, "/?.lua");
lua_concat(L, 3); lua_concat(L, 3);
lua_pushliteral(L, ";"); lua_pushliteral(L, ";");
lua_pushlstring(L, *xdgconfigdirs, len); lua_pushlstring(L, *entry, len);
lua_pushliteral(L, "/awesome/?/init.lua"); lua_pushliteral(L, "/?/init.lua");
lua_concat(L, 3); lua_concat(L, 3);
lua_concat(L, 3); /* concatenate with package.path */ lua_concat(L, 3); /* concatenate with package.path */

9
luaa.h
View File

@ -39,6 +39,13 @@
signal_object_emit(L, &global_signals, "debug::deprecation", 1); \ signal_object_emit(L, &global_signals, "debug::deprecation", 1); \
} while(0) } while(0)
static inline void free_string(char **c)
{
p_delete(c);
}
DO_ARRAY(char*, string, free_string)
/** Print a warning about some Lua code. /** Print a warning about some Lua code.
* This is less mean than luaL_error() which setjmp via lua_error() and kills * This is less mean than luaL_error() which setjmp via lua_error() and kills
* everything. This only warn, it's up to you to then do what's should be done. * everything. This only warn, it's up to you to then do what's should be done.
@ -296,7 +303,7 @@ luaA_registerfct(lua_State *L, int idx, int *fct)
return luaA_register(L, idx, fct); return luaA_register(L, idx, fct);
} }
void luaA_init(xdgHandle *); void luaA_init(xdgHandle *, string_array_t *);
bool luaA_parserc(xdgHandle *, const char *, bool); bool luaA_parserc(xdgHandle *, const char *, bool);
/** Global signals */ /** Global signals */

View File

@ -9,7 +9,7 @@ awesome - awesome Fenstermanager
SYNTAX SYNTAX
-------- --------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'Datei'] [*-k* | *--check*] [*-a* | *--no-argb*] [*-r* | *--replace] *awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'Datei'] [*-k* | *--check*] [*--search* 'Verzeichnis'] [*-a* | *--no-argb*] [*-r* | *--replace]
BESCHREIBUNG BESCHREIBUNG
----------- -----------
@ -33,6 +33,8 @@ OPTIONEN
Nutzung einer alternativen Konfigurationsdatei, statt '$XDG_CONFIG_HOME/awesome/rc.lua'. Nutzung einer alternativen Konfigurationsdatei, statt '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*:: *-k*, *--check*::
Überprüft die Konfigurationsdatei auf Syntaxfehler. Überprüft die Konfigurationsdatei auf Syntaxfehler.
*--search*::
Füge ein Verzeichnis zum Bibliothekssuchpfad hinzu.
*-a*, *--no-argb*:: *-a*, *--no-argb*::
Verwende keine ARGB-Visuals Verwende keine ARGB-Visuals
*-r*, *--replace*:: *-r*, *--replace*::

View File

@ -9,7 +9,7 @@ awesome - gestor de ventanas awesome
SINOPSIS SINOPSIS
-------- --------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FICHERO'] [*-k* | *--check*] [*-a* | *--no-argb*] [*-r* | *--replace] *awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FICHERO'] [*-k* | *--check*] [*--search* 'DIRECTORIO'] [*-a* | *--no-argb*] [*-r* | *--replace]
DESCRIPCIÓN DESCRIPCIÓN
----------- -----------
@ -50,6 +50,8 @@ OPCIONES
'$XDG_CONFIG_HOME/awesome/rc.lua'. '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*:: *-k*, *--check*::
Verifica la sintaxis del archivo de configuración. Verifica la sintaxis del archivo de configuración.
*--search*::
Añadir un directorio a la ruta de búsqueda de biblioteca.
*-a*, *--no-argb*:: *-a*, *--no-argb*::
No utilice colores ARGB. No utilice colores ARGB.
*-r*, *--replace*:: *-r*, *--replace*::

View File

@ -9,7 +9,7 @@ awesome - gestionnaire de fenêtres awesome
SYNOPSIS SYNOPSIS
-------- --------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*-a* | *--no-argb*] [*-r* | *--replace] *awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*--search* 'DIRECTORY'] [*-a* | *--no-argb*] [*-r* | *--replace]
DESCRIPTION DESCRIPTION
----------- -----------
@ -43,6 +43,8 @@ OPTIONS
'$XDG_CONFIG_HOME/awesome/rc.lua'. '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*:: *-k*, *--check*::
Vérifie la syntaxe du fichier de configuration. Vérifie la syntaxe du fichier de configuration.
*--search*::
Ajouter un répertoire au chemin de recherche de bibliothèque.
*-a*, *--no-argb*:: *-a*, *--no-argb*::
N'utilise pas le codage ARGB. N'utilise pas le codage ARGB.
*-r*, *--replace*:: *-r*, *--replace*::

View File

@ -10,7 +10,7 @@ awesome - gestore di finestre awesome
SINOSSI SINOSSI
-------- --------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*-a* | *--no-argb*] [*-r* | *--replace] *awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*--search* 'DIRECTORY'] [*-a* | *--no-argb*] [*-r* | *--replace]
DESCRIZIONE DESCRIZIONE
----------- -----------
@ -50,6 +50,8 @@ OPZIONI
'$XDG_CONFIG_HOME/awesome/rc.lua'. '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*:: *-k*, *--check*::
Verifica la sintassi del file di configurazione. Verifica la sintassi del file di configurazione.
*--search*::
Aggiungere una directory al percorso di ricerca della libreria.
*-a*, *--no-argb*:: *-a*, *--no-argb*::
Non usare visuali ARGB. Non usare visuali ARGB.
*-r*, *--replace*:: *-r*, *--replace*::

View File

@ -9,7 +9,7 @@ awesome - потрясающий оконный менеджер
СИНОПСИС СИНОПСИС
-------- --------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*-a* | *--no-argb*] [*-r* | *--replace] *awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*--search* 'DIRECTORY'] [*-a* | *--no-argb*] [*-r* | *--replace]
ОПИСАНИЕ ОПИСАНИЕ
-------- --------
@ -45,6 +45,8 @@ awesome - потрясающий оконный менеджер
Использовать альтернативный конфигурационный файл вместо '$XDG_CONFIG_HOME/awesome/rc.lua'. Использовать альтернативный конфигурационный файл вместо '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*:: *-k*, *--check*::
Проверить синтаксис конфигурационного файла. Проверить синтаксис конфигурационного файла.
*--search*::
Добавить каталог в пути поиска библиотеки.
*-a*, *--no-argb*:: *-a*, *--no-argb*::
Не использовать ARGB. Не использовать ARGB.
*-r*, *--replace*:: *-r*, *--replace*::

View File

@ -9,7 +9,7 @@ awesome - awesome window manager
SYNOPSIS SYNOPSIS
-------- --------
*awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*-a* | *--no-argb*] [*-r* | *--replace] *awesome* [*-v* | *--version*] [*-h* | *--help*] [*-c* | *--config* 'FILE'] [*-k* | *--check*] [*--search* 'DIRECTORY'] [*-a* | *--no-argb*] [*-r* | *--replace]
DESCRIPTION DESCRIPTION
----------- -----------
@ -42,6 +42,8 @@ OPTIONS
Use an alternate configuration file instead of '$XDG_CONFIG_HOME/awesome/rc.lua'. Use an alternate configuration file instead of '$XDG_CONFIG_HOME/awesome/rc.lua'.
*-k*, *--check*:: *-k*, *--check*::
Check configuration file syntax. Check configuration file syntax.
*--search*::
Add a directory to the library search path.
*-a*, *--no-argb*:: *-a*, *--no-argb*::
Don't use ARGB visuals. Don't use ARGB visuals.
*-r*, *--replace*:: *-r*, *--replace*::