lua: expand package.path more

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-30 18:20:19 +02:00
parent 330f4304c0
commit 18fab522f9
2 changed files with 10 additions and 2 deletions

10
lua.c
View File

@ -562,7 +562,7 @@ luaA_parserc(const char *confpatharg)
{ {
int screen; int screen;
const char *confdir, *xdg_config_dirs; const char *confdir, *xdg_config_dirs;
char *confpath = NULL, **xdg_files, **buf; char *confpath = NULL, **xdg_files, **buf, path[1024];
ssize_t len; ssize_t len;
if(confpatharg) if(confpatharg)
@ -580,6 +580,9 @@ luaA_parserc(const char *confpatharg)
len += sizeof(AWESOME_CONFIG_FILE); len += sizeof(AWESOME_CONFIG_FILE);
confpath = p_new(char, len); confpath = p_new(char, len);
a_strcpy(confpath, len, confdir); a_strcpy(confpath, len, confdir);
/* update package.path */
snprintf(path, sizeof(path) - 1, "package.path = package.path .. \";%s/awesome/?.lua\"", confdir);
luaA_dostring(globalconf.L, path);
} }
else else
{ {
@ -588,6 +591,9 @@ luaA_parserc(const char *confpatharg)
confpath = p_new(char, len); confpath = p_new(char, len);
a_strcpy(confpath, len, confdir); a_strcpy(confpath, len, confdir);
a_strcat(confpath, len, XDG_CONFIG_HOME_DEFAULT); a_strcat(confpath, len, XDG_CONFIG_HOME_DEFAULT);
/* update package.path */
snprintf(path, sizeof(path) - 1, "package.path = package.path .. \";%s" XDG_CONFIG_HOME_DEFAULT "/awesome/?.lua\"", confdir);
luaA_dostring(globalconf.L, path);
} }
a_strcat(confpath, len, AWESOME_CONFIG_FILE); a_strcat(confpath, len, AWESOME_CONFIG_FILE);
@ -613,6 +619,8 @@ luaA_parserc(const char *confpatharg)
confpath = p_new(char, len); confpath = p_new(char, len);
a_strcpy(confpath, len, *buf); a_strcpy(confpath, len, *buf);
a_strcat(confpath, len, AWESOME_CONFIG_FILE); a_strcat(confpath, len, AWESOME_CONFIG_FILE);
snprintf(path, sizeof(path) - 1, "package.path = package.path .. \";%s/awesome/?.lua\"", *buf);
luaA_dostring(globalconf.L, path);
if(luaL_dofile(globalconf.L, confpath)) if(luaL_dofile(globalconf.L, confpath))
fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1)); fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
else else

2
lua.h
View File

@ -71,7 +71,7 @@ typedef int luaA_function;
#define luaA_dostring(L, cmd) \ #define luaA_dostring(L, cmd) \
do { \ do { \
if(cmd) \ if(a_strlen(cmd)) \
if(luaL_dostring(L, cmd)) \ if(luaL_dostring(L, cmd)) \
warn("error executing Lua code: %s", \ warn("error executing Lua code: %s", \
lua_tostring(L, -1)); \ lua_tostring(L, -1)); \