2009-05-15 18:08:51 +00:00
|
|
|
/* Conky, a system monitor, based on torsmo
|
|
|
|
*
|
2009-05-15 18:48:11 +00:00
|
|
|
* Copyright (c) 2009 Toni Spets
|
2009-05-15 18:08:51 +00:00
|
|
|
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
|
|
|
* (see AUTHORS)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "conky.h"
|
2009-05-15 18:48:11 +00:00
|
|
|
#include "logging.h"
|
2009-07-08 08:09:06 +00:00
|
|
|
#include "build.h"
|
2009-05-15 18:08:51 +00:00
|
|
|
|
2009-05-20 04:49:42 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
#include <sys/inotify.h>
|
|
|
|
|
|
|
|
void llua_append_notify(const char *name);
|
|
|
|
void llua_rm_notifies(void);
|
|
|
|
static int llua_block_notify = 0;
|
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
|
|
|
|
2009-07-08 08:09:06 +00:00
|
|
|
static char *draw_pre = 0;
|
|
|
|
static char *draw_post = 0;
|
|
|
|
|
2009-05-15 18:08:51 +00:00
|
|
|
lua_State *lua_L = NULL;
|
|
|
|
|
2009-07-08 08:09:06 +00:00
|
|
|
static int llua_conky_parse(lua_State *L)
|
|
|
|
{
|
|
|
|
int n = lua_gettop(L); /* number of arguments */
|
|
|
|
char *str;
|
|
|
|
char *buf = calloc(1, max_user_text);
|
|
|
|
if (n != 1) {
|
|
|
|
lua_pushstring(L, "incorrect arguments, conky_parse(string) takes exactly 1 argument");
|
|
|
|
lua_error(L);
|
|
|
|
}
|
|
|
|
if (!lua_isstring(L, 1)) {
|
|
|
|
lua_pushstring(L, "incorrect argument (expecting a string)");
|
|
|
|
lua_error(L);
|
|
|
|
}
|
|
|
|
str = strdup(lua_tostring(L, 1));
|
|
|
|
evaluate(str, buf);
|
|
|
|
lua_pushstring(L, buf);
|
|
|
|
free(str);
|
|
|
|
free(buf);
|
|
|
|
return 1; /* number of results */
|
|
|
|
}
|
|
|
|
|
2009-05-16 23:04:26 +00:00
|
|
|
void llua_init(void)
|
2009-05-15 18:08:51 +00:00
|
|
|
{
|
2009-07-08 08:09:06 +00:00
|
|
|
const char *libs = PACKAGE_LIBDIR"/lib?.so;";
|
|
|
|
char *old_path, *new_path;
|
|
|
|
if (lua_L) return;
|
2009-05-15 18:08:51 +00:00
|
|
|
lua_L = lua_open();
|
2009-07-08 08:09:06 +00:00
|
|
|
|
|
|
|
/* add our library path to the lua package.cpath global var */
|
2009-05-15 18:08:51 +00:00
|
|
|
luaL_openlibs(lua_L);
|
2009-07-08 08:09:06 +00:00
|
|
|
lua_getglobal(lua_L, "package");
|
|
|
|
lua_getfield(lua_L, -1, "cpath");
|
|
|
|
old_path = strdup(lua_tostring(lua_L, -1));
|
|
|
|
new_path = malloc(strlen(old_path) + strlen(libs) + 1);
|
|
|
|
strcpy(new_path, libs);
|
|
|
|
strcat(new_path, old_path);
|
|
|
|
lua_pushstring(lua_L, new_path);
|
|
|
|
lua_setfield(lua_L, -3, "cpath");
|
|
|
|
lua_pop(lua_L, 2);
|
|
|
|
free(old_path);
|
|
|
|
free(new_path);
|
|
|
|
|
|
|
|
lua_pushstring(lua_L, PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH);
|
|
|
|
lua_setglobal(lua_L, "conky_build_info");
|
|
|
|
|
|
|
|
lua_pushstring(lua_L, VERSION);
|
|
|
|
lua_setglobal(lua_L, "conky_version");
|
|
|
|
|
2009-07-18 19:46:36 +00:00
|
|
|
lua_pushstring(lua_L, BUILD_DATE);
|
|
|
|
lua_setglobal(lua_L, "conky_build_date");
|
|
|
|
|
|
|
|
lua_pushstring(lua_L, BUILD_ARCH);
|
|
|
|
lua_setglobal(lua_L, "conky_build_arch");
|
|
|
|
|
2009-07-08 08:09:06 +00:00
|
|
|
lua_pushstring(lua_L, current_config);
|
|
|
|
lua_setglobal(lua_L, "conky_config");
|
|
|
|
|
|
|
|
lua_pushcfunction(lua_L, &llua_conky_parse);
|
|
|
|
lua_setglobal(lua_L, "conky_parse");
|
2009-05-15 18:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void llua_load(const char *script)
|
|
|
|
{
|
|
|
|
int error;
|
2009-05-25 04:33:47 +00:00
|
|
|
char path[DEFAULT_TEXT_BUFFER_SIZE];
|
|
|
|
|
2009-07-08 08:09:06 +00:00
|
|
|
llua_init();
|
2009-05-25 04:33:47 +00:00
|
|
|
|
|
|
|
to_real_path(path, script);
|
|
|
|
error = luaL_dofile(lua_L, path);
|
2009-05-16 20:55:05 +00:00
|
|
|
if (error) {
|
2009-05-15 20:01:08 +00:00
|
|
|
ERR("llua_load: %s", lua_tostring(lua_L, -1));
|
2009-05-15 18:08:51 +00:00
|
|
|
lua_pop(lua_L, 1);
|
2009-05-20 04:56:33 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
2009-06-13 19:17:18 +00:00
|
|
|
} else if (!llua_block_notify && inotify_fd != -1) {
|
2009-06-13 19:40:27 +00:00
|
|
|
llua_append_notify(path);
|
2009-05-20 04:56:33 +00:00
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
2009-05-15 18:08:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-16 17:57:43 +00:00
|
|
|
/*
|
|
|
|
llua_do_call does a flexible call to any Lua function
|
|
|
|
string: <function> [par1] [par2...]
|
|
|
|
retc: the number of return values expected
|
|
|
|
*/
|
|
|
|
char *llua_do_call(const char *string, int retc)
|
2009-05-15 18:08:51 +00:00
|
|
|
{
|
2009-05-16 17:57:43 +00:00
|
|
|
static char func[64];
|
|
|
|
int argc = 0;
|
2009-05-15 18:08:51 +00:00
|
|
|
|
2009-05-16 17:57:43 +00:00
|
|
|
char *tmp = strdup(string);
|
2009-05-15 18:08:51 +00:00
|
|
|
char *ptr = strtok(tmp, " ");
|
2009-05-16 17:57:43 +00:00
|
|
|
|
|
|
|
/* proceed only if the function name is present */
|
2009-07-08 08:09:06 +00:00
|
|
|
if (!ptr) {
|
2009-05-16 17:57:43 +00:00
|
|
|
free(tmp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call only conky_ prefixed functions */
|
2009-07-25 10:03:09 +00:00
|
|
|
if(strncmp(ptr, LUAPREFIX, strlen(LUAPREFIX)) == 0) {
|
|
|
|
snprintf(func, 64, "%s", ptr);
|
|
|
|
}else{
|
|
|
|
snprintf(func, 64, "%s%s", LUAPREFIX, ptr);
|
|
|
|
}
|
2009-05-15 18:08:51 +00:00
|
|
|
|
2009-05-16 17:57:43 +00:00
|
|
|
/* push the function name to stack */
|
2009-05-15 18:08:51 +00:00
|
|
|
lua_getglobal(lua_L, func);
|
|
|
|
|
2009-05-16 17:57:43 +00:00
|
|
|
/* parse all function parameters from args and push them to the stack */
|
2009-05-15 18:08:51 +00:00
|
|
|
ptr = strtok(NULL, " ");
|
2009-07-08 08:09:06 +00:00
|
|
|
while (ptr) {
|
2009-05-15 18:08:51 +00:00
|
|
|
lua_pushstring(lua_L, ptr);
|
|
|
|
ptr = strtok(NULL, " ");
|
2009-05-16 17:57:43 +00:00
|
|
|
argc++;
|
2009-05-15 18:08:51 +00:00
|
|
|
}
|
|
|
|
|
2009-05-16 17:57:43 +00:00
|
|
|
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));
|
2009-05-15 18:08:51 +00:00
|
|
|
lua_pop(lua_L, -1);
|
2009-05-16 17:57:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2009-05-16 23:04:26 +00:00
|
|
|
/*
|
|
|
|
* same as llua_do_call() except passes everything after func as one arg.
|
|
|
|
*/
|
|
|
|
char *llua_do_read_call(const char *function, const char *arg, int retc)
|
|
|
|
{
|
|
|
|
static char func[64];
|
|
|
|
snprintf(func, 64, "conky_%s", function);
|
|
|
|
|
|
|
|
/* push the function name to stack */
|
|
|
|
lua_getglobal(lua_L, func);
|
|
|
|
|
|
|
|
/* push function parameter to the stack */
|
|
|
|
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));
|
|
|
|
lua_pop(lua_L, -1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2009-05-16 17:57:43 +00:00
|
|
|
char *llua_getstring(const char *args)
|
|
|
|
{
|
|
|
|
char *func;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if(!lua_L) return NULL;
|
|
|
|
|
|
|
|
func = llua_do_call(args, 1);
|
2009-07-08 08:09:06 +00:00
|
|
|
if (func) {
|
|
|
|
if (!lua_isstring(lua_L, -1)) {
|
2009-05-15 20:01:08 +00:00
|
|
|
ERR("llua_getstring: function %s didn't return a string, result discarded", func);
|
2009-05-15 18:08:51 +00:00
|
|
|
} else {
|
2009-05-16 23:04:26 +00:00
|
|
|
ret = strdup(lua_tostring(lua_L, -1));
|
|
|
|
lua_pop(lua_L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *llua_getstring_read(const char *function, const char *arg)
|
|
|
|
{
|
|
|
|
char *func;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if(!lua_L) return NULL;
|
|
|
|
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
ret = strdup(lua_tostring(lua_L, -1));
|
2009-05-15 18:08:51 +00:00
|
|
|
lua_pop(lua_L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-06 23:42:02 +00:00
|
|
|
int llua_getnumber(const char *args, double *ret)
|
2009-05-15 18:08:51 +00:00
|
|
|
{
|
2009-05-16 17:57:43 +00:00
|
|
|
char *func;
|
2009-05-15 18:08:51 +00:00
|
|
|
|
|
|
|
if(!lua_L) return 0;
|
|
|
|
|
2009-05-16 17:57:43 +00:00
|
|
|
func = llua_do_call(args, 1);
|
|
|
|
if(func) {
|
2009-05-15 18:08:51 +00:00
|
|
|
if(!lua_isnumber(lua_L, -1)) {
|
2009-06-06 23:25:34 +00:00
|
|
|
ERR("llua_getnumber: function %s didn't return a number, result discarded", func);
|
2009-05-15 18:08:51 +00:00
|
|
|
} else {
|
2009-06-06 23:42:02 +00:00
|
|
|
*ret = lua_tonumber(lua_L, -1);
|
2009-05-15 18:08:51 +00:00
|
|
|
lua_pop(lua_L, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-16 23:04:26 +00:00
|
|
|
void llua_close(void)
|
2009-05-15 18:08:51 +00:00
|
|
|
{
|
2009-05-20 04:56:33 +00:00
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
2009-05-20 04:49:42 +00:00
|
|
|
llua_rm_notifies();
|
2009-05-20 04:56:33 +00:00
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
2009-07-08 08:09:06 +00:00
|
|
|
if (draw_pre) {
|
|
|
|
free(draw_pre);
|
|
|
|
draw_pre = 0;
|
|
|
|
}
|
|
|
|
if (draw_post) {
|
|
|
|
free(draw_post);
|
|
|
|
draw_post = 0;
|
|
|
|
}
|
2009-05-15 18:08:51 +00:00
|
|
|
if(!lua_L) return;
|
|
|
|
lua_close(lua_L);
|
|
|
|
lua_L = NULL;
|
|
|
|
}
|
2009-05-20 04:49:42 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_INOTIFY_H
|
|
|
|
struct _lua_notify_s {
|
|
|
|
int wd;
|
|
|
|
char name[DEFAULT_TEXT_BUFFER_SIZE];
|
|
|
|
struct _lua_notify_s *next;
|
|
|
|
};
|
|
|
|
static struct _lua_notify_s *lua_notifies = 0;
|
|
|
|
|
|
|
|
static struct _lua_notify_s *llua_notify_list_do_alloc(const char *name)
|
|
|
|
{
|
|
|
|
struct _lua_notify_s *ret = malloc(sizeof(struct _lua_notify_s));
|
|
|
|
memset(ret, 0, sizeof(struct _lua_notify_s));
|
|
|
|
strncpy(ret->name, name, DEFAULT_TEXT_BUFFER_SIZE);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void llua_append_notify(const char *name)
|
|
|
|
{
|
|
|
|
/* do it */
|
|
|
|
struct _lua_notify_s *new_tail = 0;
|
|
|
|
if (!lua_notifies) {
|
|
|
|
/* empty, fresh new digs */
|
|
|
|
new_tail = lua_notifies = llua_notify_list_do_alloc(name);
|
|
|
|
} else {
|
|
|
|
struct _lua_notify_s *tail = lua_notifies;
|
|
|
|
while (tail->next) {
|
|
|
|
tail = tail->next;
|
|
|
|
}
|
|
|
|
// should be @ the end now
|
|
|
|
new_tail = llua_notify_list_do_alloc(name);
|
|
|
|
tail->next = new_tail;
|
|
|
|
}
|
|
|
|
new_tail->wd = inotify_add_watch(inotify_fd,
|
|
|
|
new_tail->name,
|
|
|
|
IN_MODIFY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llua_rm_notifies(void)
|
|
|
|
{
|
|
|
|
/* git 'er done */
|
|
|
|
struct _lua_notify_s *head = lua_notifies;
|
2009-05-20 17:53:43 +00:00
|
|
|
struct _lua_notify_s *next = 0;
|
2009-05-20 04:49:42 +00:00
|
|
|
if (!lua_notifies) return;
|
|
|
|
inotify_rm_watch(inotify_fd, head->wd);
|
2009-05-20 17:53:43 +00:00
|
|
|
if (head->next) next = head->next;
|
2009-05-20 04:49:42 +00:00
|
|
|
free(head);
|
|
|
|
while (next) {
|
|
|
|
head = next;
|
|
|
|
next = head->next;
|
|
|
|
inotify_rm_watch(inotify_fd, head->wd);
|
|
|
|
free(head);
|
|
|
|
}
|
|
|
|
lua_notifies = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void llua_inotify_query(int wd, int mask)
|
|
|
|
{
|
|
|
|
struct _lua_notify_s *head = lua_notifies;
|
|
|
|
if (mask & IN_MODIFY || mask & IN_IGNORED) {
|
|
|
|
/* for whatever reason, i keep getting IN_IGNORED when the file is
|
|
|
|
* modified */
|
|
|
|
while (head) {
|
|
|
|
if (head->wd == wd) {
|
|
|
|
llua_block_notify = 1;
|
|
|
|
llua_load(head->name);
|
|
|
|
llua_block_notify = 0;
|
2009-05-20 04:51:50 +00:00
|
|
|
ERR("Lua script '%s' reloaded", head->name);
|
2009-05-20 04:49:42 +00:00
|
|
|
if (mask & IN_IGNORED) {
|
|
|
|
/* for some reason we get IN_IGNORED here
|
|
|
|
* sometimes, so we need to re-add the watch */
|
|
|
|
head->wd = inotify_add_watch(inotify_fd,
|
|
|
|
head->name,
|
|
|
|
IN_MODIFY);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
head = head->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_SYS_INOTIFY_H */
|
|
|
|
|
2009-07-10 16:07:39 +00:00
|
|
|
#ifdef X11
|
2009-07-08 08:09:06 +00:00
|
|
|
void llua_draw_pre_hook(void)
|
|
|
|
{
|
|
|
|
if (!lua_L || !draw_pre) return;
|
|
|
|
llua_do_call(draw_pre, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llua_draw_post_hook(void)
|
|
|
|
{
|
|
|
|
if (!lua_L || !draw_post) return;
|
|
|
|
llua_do_call(draw_post, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llua_set_draw_pre_hook(const char *args)
|
|
|
|
{
|
|
|
|
draw_pre = strdup(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llua_set_draw_post_hook(const char *args)
|
|
|
|
{
|
|
|
|
draw_post = strdup(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llua_set_long(const char *key, long value)
|
|
|
|
{
|
|
|
|
lua_pushnumber(lua_L, value);
|
|
|
|
lua_setfield(lua_L, -2, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this function mostly copied from tolua++ source so that we could play nice
|
|
|
|
* with tolua++ libs. tolua++ is provided 'as is'
|
|
|
|
*/
|
|
|
|
void llua_set_userdata(const char *key, const char *type, void *value)
|
|
|
|
{
|
|
|
|
if (value == NULL) {
|
|
|
|
lua_pushnil(lua_L);
|
|
|
|
} else {
|
|
|
|
luaL_getmetatable(lua_L, type);
|
|
|
|
lua_pushstring(lua_L,"tolua_ubox");
|
|
|
|
lua_rawget(lua_L,-2); /* stack: mt ubox */
|
|
|
|
if (lua_isnil(lua_L, -1)) {
|
|
|
|
lua_pop(lua_L, 1);
|
|
|
|
lua_pushstring(lua_L, "tolua_ubox");
|
|
|
|
lua_rawget(lua_L, LUA_REGISTRYINDEX);
|
|
|
|
}
|
|
|
|
lua_pushlightuserdata(lua_L,value);
|
|
|
|
lua_rawget(lua_L,-2); /* stack: mt ubox ubox[u] */
|
|
|
|
if (lua_isnil(lua_L,-1)) {
|
|
|
|
lua_pop(lua_L,1); /* stack: mt ubox */
|
|
|
|
lua_pushlightuserdata(lua_L,value);
|
|
|
|
*(void**)lua_newuserdata(lua_L,sizeof(void *)) = value; /* stack: mt ubox u newud */
|
|
|
|
lua_pushvalue(lua_L,-1); /* stack: mt ubox u newud newud */
|
|
|
|
lua_insert(lua_L,-4); /* stack: mt newud ubox u newud */
|
|
|
|
lua_rawset(lua_L,-3); /* stack: mt newud ubox */
|
|
|
|
lua_pop(lua_L,1); /* stack: mt newud */
|
|
|
|
/*luaL_getmetatable(lua_L,type);*/
|
|
|
|
lua_pushvalue(lua_L, -2); /* stack: mt newud mt */
|
|
|
|
lua_setmetatable(lua_L,-2); /* stack: mt newud */
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* check the need of updating the metatable to a more specialized class */
|
|
|
|
lua_insert(lua_L,-2); /* stack: mt ubox[u] ubox */
|
|
|
|
lua_pop(lua_L,1); /* stack: mt ubox[u] */
|
|
|
|
lua_pushstring(lua_L,"tolua_super");
|
|
|
|
lua_rawget(lua_L,LUA_REGISTRYINDEX); /* stack: mt ubox[u] super */
|
|
|
|
lua_getmetatable(lua_L,-2); /* stack: mt ubox[u] super mt */
|
|
|
|
lua_rawget(lua_L,-2); /* stack: mt ubox[u] super super[mt] */
|
|
|
|
if (lua_istable(lua_L,-1)) {
|
|
|
|
lua_pushstring(lua_L,type); /* stack: mt ubox[u] super super[mt] type */
|
|
|
|
lua_rawget(lua_L,-2); /* stack: mt ubox[u] super super[mt] flag */
|
|
|
|
if (lua_toboolean(lua_L,-1) == 1) {
|
|
|
|
/* if true */
|
|
|
|
lua_pop(lua_L,3); /* mt ubox[u]*/
|
|
|
|
lua_remove(lua_L, -2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* type represents a more specilized type */
|
|
|
|
/*luaL_getmetatable(lua_L,type); // stack: mt ubox[u] super super[mt] flag mt */
|
|
|
|
lua_pushvalue(lua_L, -5); /* stack: mt ubox[u] super super[mt] flag mt */
|
|
|
|
lua_setmetatable(lua_L,-5); /* stack: mt ubox[u] super super[mt] flag */
|
|
|
|
lua_pop(lua_L,3); /* stack: mt ubox[u] */
|
|
|
|
}
|
|
|
|
lua_remove(lua_L, -2); /* stack: ubox[u]*/
|
|
|
|
}
|
|
|
|
lua_setfield(lua_L, -2, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llua_setup_window_table(int text_start_x, int text_start_y, int text_width, int text_height)
|
|
|
|
{
|
2009-07-13 03:38:35 +00:00
|
|
|
if (!lua_L) return;
|
2009-07-08 08:09:06 +00:00
|
|
|
lua_newtable(lua_L);
|
|
|
|
|
2009-07-25 00:42:31 +00:00
|
|
|
if (output_methods & TO_X) {
|
|
|
|
llua_set_userdata("drawable", "Drawable", (void*)&window.drawable);
|
|
|
|
llua_set_userdata("visual", "Visual", window.visual);
|
|
|
|
llua_set_userdata("display", "Display", display);
|
2009-07-13 03:38:35 +00:00
|
|
|
|
2009-07-08 08:09:06 +00:00
|
|
|
|
2009-07-25 00:42:31 +00:00
|
|
|
llua_set_long("width", window.width);
|
|
|
|
llua_set_long("height", window.height);
|
|
|
|
llua_set_long("border_inner_margin", window.border_inner_margin);
|
|
|
|
llua_set_long("border_outer_margin", window.border_outer_margin);
|
|
|
|
llua_set_long("border_width", window.border_width);
|
2009-07-08 08:09:06 +00:00
|
|
|
|
2009-07-25 00:42:31 +00:00
|
|
|
llua_set_long("text_start_x", text_start_x);
|
|
|
|
llua_set_long("text_start_y", text_start_y);
|
|
|
|
llua_set_long("text_width", text_width);
|
|
|
|
llua_set_long("text_height", text_height);
|
2009-07-08 08:09:06 +00:00
|
|
|
|
2009-07-25 00:42:31 +00:00
|
|
|
lua_setglobal(lua_L, "conky_window");
|
|
|
|
}
|
2009-07-08 08:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void llua_update_window_table(int text_start_x, int text_start_y, int text_width, int text_height)
|
|
|
|
{
|
2009-07-13 03:38:35 +00:00
|
|
|
if (!lua_L) return;
|
|
|
|
|
2009-07-08 08:09:06 +00:00
|
|
|
lua_getglobal(lua_L, "conky_window");
|
|
|
|
if (lua_isnil(lua_L, -1)) {
|
|
|
|
/* window table isn't populated yet */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
llua_set_long("width", window.width);
|
|
|
|
llua_set_long("height", window.height);
|
|
|
|
|
|
|
|
llua_set_long("text_start_x", text_start_x);
|
|
|
|
llua_set_long("text_start_y", text_start_y);
|
|
|
|
llua_set_long("text_width", text_width);
|
|
|
|
llua_set_long("text_height", text_height);
|
|
|
|
|
|
|
|
lua_setglobal(lua_L, "conky_window");
|
|
|
|
}
|
2009-07-10 16:07:39 +00:00
|
|
|
#endif /* X11 */
|
2009-07-08 08:09:06 +00:00
|
|
|
|