1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-29 21:49:07 +00:00

Make lua_load a lua setting

This commit is contained in:
Pavel Labath 2010-08-29 15:45:38 +02:00
parent b1891474e7
commit 26cb39f67c
3 changed files with 54 additions and 31 deletions

View File

@ -2566,7 +2566,6 @@ void clean_up_without_threads(void *memtofree1, void* memtofree2)
#endif
#ifdef BUILD_LUA
llua_shutdown_hook();
llua_close();
#endif /* BUILD_LUA */
#if defined BUILD_WEATHER_XOAP || defined BUILD_RSS
xmlCleanupParser();
@ -2897,17 +2896,6 @@ char load_config_file(const char *f)
break;
}
#ifdef BUILD_LUA
CONF("lua_load") {
if (value) {
char *ptr = strtok(value, " ");
while (ptr) {
llua_load(ptr);
ptr = strtok(NULL, " ");
}
} else {
CONF_ERR;
}
}
#ifdef BUILD_X11
CONF("lua_draw_hook_pre") {
if (value) {
@ -3390,7 +3378,7 @@ int main(int argc, char **argv)
"conky.config = { alignment='top_left', asdf=47, [42]=47, out_to_x=true,\n"
" own_window_hints='above, skip_taskbar',\n"
" background_colour='pink', own_window=true, double_buffer=true,\n"
" mpd_port=-47};\n"
" lua_load='asdf qq/q'};\n"
);
l.call(0, 0);
conky::set_config_settings(l);

View File

@ -42,6 +42,8 @@ void llua_rm_notifies(void);
static int llua_block_notify = 0;
#endif /* HAVE_SYS_INOTIFY_H */
static void llua_load(const char *script);
#define MIN(a, b) ( (a) < (b) ? (a) : (b) )
static char *draw_pre_hook = 0;
@ -51,6 +53,57 @@ static char *shutdown_hook = 0;
lua_State *lua_L = NULL;
namespace {
class lua_load_setting: public conky::simple_config_setting<std::string> {
typedef conky::simple_config_setting<std::string> Base;
protected:
void lua_setter(lua::state &l, bool init)
{
lua::stack_sentry s(l, -2);
Base::lua_setter(l, init);
if(init) {
std::string files = do_convert(l, -1).first;
while(not files.empty()) {
std::string::size_type pos = files.find(' ');
if(pos > 0) {
std::string file(files, 0, pos);
llua_load(file.c_str());
}
files.erase(0, pos==std::string::npos ? pos : pos+1);
}
}
++s;
}
void cleanup(lua::state &l)
{
lua::stack_sentry s(l, -1);
#ifdef HAVE_SYS_INOTIFY_H
llua_rm_notifies();
#endif /* HAVE_SYS_INOTIFY_H */
free_and_zero(draw_pre_hook);
free_and_zero(draw_post_hook);
free_and_zero(startup_hook);
free_and_zero(shutdown_hook);
if(!lua_L) return;
lua_close(lua_L);
lua_L = NULL;
}
public:
lua_load_setting()
: Base("lua_load", std::string(), false)
{}
};
lua_load_setting lua_load;
}
static int llua_conky_parse(lua_State *L)
{
int n = lua_gettop(L); /* number of arguments */
@ -319,20 +372,6 @@ static int llua_getnumber(const char *args, double *ret)
return 0;
}
void llua_close(void)
{
#ifdef HAVE_SYS_INOTIFY_H
llua_rm_notifies();
#endif /* HAVE_SYS_INOTIFY_H */
free_and_zero(draw_pre_hook);
free_and_zero(draw_post_hook);
free_and_zero(startup_hook);
free_and_zero(shutdown_hook);
if(!lua_L) return;
lua_close(lua_L);
lua_L = NULL;
}
#ifdef HAVE_SYS_INOTIFY_H
struct _lua_notify_s {
int wd;

View File

@ -39,10 +39,6 @@ extern "C" {
#define LUAPREFIX "conky_"
/* load a lua script */
void llua_load(const char *script);
/* close lua stuff */
void llua_close(void);
#ifdef HAVE_SYS_INOTIFY_H
/* check our lua inotify status */
void llua_inotify_query(int wd, int mask);