static int llua_block_notify = 0;
#endif /* HAVE_SYS_INOTIFY_H */
-static char *draw_pre = 0;
-static char *draw_post = 0;
+static char *draw_pre_hook = 0;
+static char *draw_post_hook = 0;
+static char *startup_hook = 0;
+static char *shutdown_hook = 0;
lua_State *lua_L = NULL;
to_real_path(path, script);
error = luaL_dofile(lua_L, path);
if (error) {
- ERR("llua_load: %s", lua_tostring(lua_L, -1));
+ NORM_ERR("llua_load: %s", lua_tostring(lua_L, -1));
lua_pop(lua_L, 1);
#ifdef HAVE_SYS_INOTIFY_H
} else if (!llua_block_notify && inotify_fd != -1) {
free(tmp);
if(lua_pcall(lua_L, argc, retc, 0) != 0) {
- ERR("llua_do_call: function %s execution failed: %s", func, lua_tostring(lua_L, -1));
+ NORM_ERR("llua_do_call: function %s execution failed: %s", func, lua_tostring(lua_L, -1));
lua_pop(lua_L, -1);
return NULL;
}
lua_pushstring(lua_L, arg);
if (lua_pcall(lua_L, 1, retc, 0) != 0) {
- ERR("llua_do_call: function %s execution failed: %s", func, lua_tostring(lua_L, -1));
+ NORM_ERR("llua_do_call: function %s execution failed: %s", func, lua_tostring(lua_L, -1));
lua_pop(lua_L, -1);
return NULL;
}
func = llua_do_call(args, 1);
if (func) {
if (!lua_isstring(lua_L, -1)) {
- ERR("llua_getstring: function %s didn't return a string, result discarded", func);
+ NORM_ERR("llua_getstring: function %s didn't return a string, result discarded", func);
} else {
ret = strdup(lua_tostring(lua_L, -1));
lua_pop(lua_L, 1);
func = llua_do_read_call(function, arg, 1);
if (func) {
if(!lua_isstring(lua_L, -1)) {
- ERR("llua_getstring_read: function %s didn't return a string, result discarded", func);
+ NORM_ERR("llua_getstring_read: function %s didn't return a string, result discarded", func);
} else {
ret = strdup(lua_tostring(lua_L, -1));
lua_pop(lua_L, 1);
func = llua_do_call(args, 1);
if(func) {
if(!lua_isnumber(lua_L, -1)) {
- ERR("llua_getnumber: function %s didn't return a number, result discarded", func);
+ NORM_ERR("llua_getnumber: function %s didn't return a number, result discarded", func);
} else {
*ret = lua_tonumber(lua_L, -1);
lua_pop(lua_L, 1);
#ifdef HAVE_SYS_INOTIFY_H
llua_rm_notifies();
#endif /* HAVE_SYS_INOTIFY_H */
- if (draw_pre) {
- free(draw_pre);
- draw_pre = 0;
+ if (draw_pre_hook) {
+ free(draw_pre_hook);
+ draw_pre_hook = 0;
}
- if (draw_post) {
- free(draw_post);
- draw_post = 0;
+ if (draw_post_hook) {
+ free(draw_post_hook);
+ draw_post_hook = 0;
}
if(!lua_L) return;
lua_close(lua_L);
llua_block_notify = 1;
llua_load(head->name);
llua_block_notify = 0;
- ERR("Lua script '%s' reloaded", head->name);
+ NORM_ERR("Lua script '%s' reloaded", head->name);
if (mask & IN_IGNORED) {
/* for some reason we get IN_IGNORED here
* sometimes, so we need to re-add the watch */
lua_setfield(lua_L, -2, key);
}
+void llua_set_startup_hook(const char *args)
+{
+ startup_hook = strdup(args);
+}
+
+void llua_set_shutdown_hook(const char *args)
+{
+ shutdown_hook = strdup(args);
+}
+
+void llua_startup_hook(void)
+{
+ if (!lua_L || !startup_hook) return;
+ llua_do_call(startup_hook, 0);
+}
+
+void llua_shutdown_hook(void)
+{
+ if (!lua_L || !shutdown_hook) return;
+ llua_do_call(shutdown_hook, 0);
+}
+
#ifdef X11
void llua_draw_pre_hook(void)
{
- if (!lua_L || !draw_pre) return;
- llua_do_call(draw_pre, 0);
+ if (!lua_L || !draw_pre_hook) return;
+ llua_do_call(draw_pre_hook, 0);
}
void llua_draw_post_hook(void)
{
- if (!lua_L || !draw_post) return;
- llua_do_call(draw_post, 0);
+ if (!lua_L || !draw_post_hook) return;
+ llua_do_call(draw_post_hook, 0);
}
void llua_set_draw_pre_hook(const char *args)
{
- draw_pre = strdup(args);
+ draw_pre_hook = strdup(args);
}
void llua_set_draw_post_hook(const char *args)
{
- draw_post = strdup(args);
+ draw_post_hook = strdup(args);
}
#ifdef LUA_EXTRAS