luaa: use only one xdgHandle for all

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-08 15:47:31 +02:00
parent 62397eac95
commit f7bca3271c
3 changed files with 17 additions and 17 deletions

View File

@ -333,6 +333,7 @@ main(int argc, char **argv)
xcolor_init_request_t colors_reqs[2]; xcolor_init_request_t colors_reqs[2];
xcb_get_modifier_mapping_cookie_t xmapping_cookie; xcb_get_modifier_mapping_cookie_t xmapping_cookie;
ssize_t cmdlen = 1; ssize_t cmdlen = 1;
xdgHandle xdg;
static struct option long_options[] = static struct option long_options[] =
{ {
{ "help", 0, NULL, 'h' }, { "help", 0, NULL, 'h' },
@ -370,8 +371,11 @@ 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 */
xdg = xdgAllocHandle();
/* init lua */ /* init lua */
luaA_init(); luaA_init(xdg);
/* check args */ /* check args */
while((opt = getopt_long(argc, argv, "vhkc:", while((opt = getopt_long(argc, argv, "vhkc:",
@ -385,7 +389,7 @@ main(int argc, char **argv)
exit_help(EXIT_SUCCESS); exit_help(EXIT_SUCCESS);
break; break;
case 'k': case 'k':
if(!luaA_parserc(confpath, false)) if(!luaA_parserc(xdg, confpath, false))
{ {
fprintf(stderr, "✘ Configuration file syntax error.\n"); fprintf(stderr, "✘ Configuration file syntax error.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
@ -522,7 +526,9 @@ main(int argc, char **argv)
} }
/* Parse and run configuration file */ /* Parse and run configuration file */
luaA_parserc(confpath, true); luaA_parserc(xdg, confpath, true);
xdgFreeHandle(xdg);
/* scan existing windows */ /* scan existing windows */
scan(); scan();

16
luaa.c
View File

@ -723,9 +723,10 @@ luaA_awesome_newindex(lua_State *L)
} }
/** Initialize the Lua VM /** Initialize the Lua VM
* \param xdg An xdg handle to use to get XDG basedir.
*/ */
void void
luaA_init(void) luaA_init(xdgHandle xdg)
{ {
lua_State *L; lua_State *L;
static const struct luaL_reg awesome_lib[] = static const struct luaL_reg awesome_lib[] =
@ -822,8 +823,6 @@ luaA_init(void)
globalconf.hooks.dbus = LUA_REFNIL; globalconf.hooks.dbus = LUA_REFNIL;
#endif #endif
xdgHandle xdg = xdgAllocHandle();
/* add Lua lib path (/usr/share/awesome/lib by default) */ /* add Lua lib path (/usr/share/awesome/lib by default) */
luaA_dostring(L, "package.path = package.path .. \";" AWESOME_LUA_LIB_PATH "/?.lua\""); luaA_dostring(L, "package.path = package.path .. \";" AWESOME_LUA_LIB_PATH "/?.lua\"");
luaA_dostring(L, "package.path = package.path .. \";" AWESOME_LUA_LIB_PATH "/?/init.lua\""); luaA_dostring(L, "package.path = package.path .. \";" AWESOME_LUA_LIB_PATH "/?/init.lua\"");
@ -838,8 +837,6 @@ luaA_init(void)
luaA_dostring(L, buf); luaA_dostring(L, buf);
p_delete(&buf); p_delete(&buf);
} }
xdgFreeHandle(xdg);
} }
static bool static bool
@ -868,16 +865,16 @@ luaA_loadrc(const char *confpath, bool run)
} }
/** Load a configuration file. /** Load a configuration file.
* \param xdg An xdg handle to use to get XDG basedir.
* \param confpatharg The configuration file to load. * \param confpatharg The configuration file to load.
* \param run Run the configuration file. * \param run Run the configuration file.
*/ */
bool bool
luaA_parserc(const char *confpatharg, bool run) luaA_parserc(xdgHandle xdg, const char *confpatharg, bool run)
{ {
int screen; int screen;
char *confpath = NULL; char *confpath = NULL;
bool ret = false; bool ret = false;
xdgHandle xdg = NULL;
/* try to load, return if it's ok */ /* try to load, return if it's ok */
if(confpatharg) if(confpatharg)
@ -891,8 +888,6 @@ luaA_parserc(const char *confpatharg, bool run)
goto bailout; goto bailout;
} }
xdg = xdgAllocHandle();
confpath = xdgConfigFind("awesome/rc.lua", xdg); confpath = xdgConfigFind("awesome/rc.lua", xdg);
char *tmp = confpath; char *tmp = confpath;
@ -914,9 +909,6 @@ bailout:
p_delete(&confpath); p_delete(&confpath);
if(xdg)
xdgFreeHandle(xdg);
/* Assure there's at least one tag */ /* Assure there's at least one tag */
for(screen = 0; screen < globalconf.nscreen; screen++) for(screen = 0; screen < globalconf.nscreen; screen++)
if(!globalconf.screens[screen].tags.len) if(!globalconf.screens[screen].tags.len)

6
luaa.h
View File

@ -27,6 +27,8 @@
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <basedir.h>
#include <stdio.h> #include <stdio.h>
#include "draw.h" #include "draw.h"
@ -381,8 +383,8 @@ luaA_pushpadding(lua_State *L, padding_t *padding)
return 1; return 1;
} }
void luaA_init(void); void luaA_init(xdgHandle);
bool luaA_parserc(const char *, bool); bool luaA_parserc(xdgHandle, const char *, bool);
void luaA_cs_init(void); void luaA_cs_init(void);
void luaA_cs_cleanup(void); void luaA_cs_cleanup(void);
void luaA_on_timer(EV_P_ ev_timer *, int); void luaA_on_timer(EV_P_ ev_timer *, int);