1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 04:17:33 +00:00

lua: outsource code

This commit is contained in:
Phil Sutter 2009-11-16 21:31:51 +01:00
parent b6d1ff6c42
commit 9efa384bbc
3 changed files with 81 additions and 38 deletions

View File

@ -1278,42 +1278,20 @@ void generate_text_internal(char *p, int p_max_size,
#endif #endif
#ifdef HAVE_LUA #ifdef HAVE_LUA
OBJ(lua) { OBJ(lua) {
char *str = llua_getstring(obj->data.s); print_lua(obj, p, p_max_size);
if (str) {
snprintf(p, p_max_size, "%s", str);
free(str);
}
} }
OBJ(lua_parse) { OBJ(lua_parse) {
char *str = llua_getstring(obj->data.s); print_lua_parse(obj, p, p_max_size);
if (str) {
evaluate(str, p, p_max_size);
free(str);
}
} }
OBJ(lua_bar) { OBJ(lua_bar) {
double per; print_lua_bar(obj, p, p_max_size);
if (llua_getnumber(obj->data.s, &per)) {
#ifdef X11
if(output_methods & TO_X) {
new_bar(obj, p, (per/100.0 * 255));
} else
#endif /* X11 */
new_bar_in_shell(obj, p, p_max_size, per);
}
} }
#ifdef X11 #ifdef X11
OBJ(lua_graph) { OBJ(lua_graph) {
double per; print_lua_graph(obj, p, p_max_size);
if (llua_getnumber(obj->data.s, &per)) {
new_graph(obj, p, per);
}
} }
OBJ(lua_gauge) { OBJ(lua_gauge) {
double per; print_lua_gauge(obj, p, p_max_size);
if (llua_getnumber(obj->data.s, &per)) {
new_gauge(obj, p, (per/100.0 * 255));
}
} }
#endif /* X11 */ #endif /* X11 */
#endif /* HAVE_LUA */ #endif /* HAVE_LUA */

View File

@ -158,7 +158,7 @@ void llua_load(const char *script)
string: <function> [par1] [par2...] string: <function> [par1] [par2...]
retc: the number of return values expected retc: the number of return values expected
*/ */
char *llua_do_call(const char *string, int retc) static char *llua_do_call(const char *string, int retc)
{ {
static char func[64]; static char func[64];
int argc = 0; int argc = 0;
@ -201,10 +201,11 @@ char *llua_do_call(const char *string, int retc)
return func; return func;
} }
#if 0
/* /*
* same as llua_do_call() except passes everything after func as one arg. * 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 *llua_do_read_call(const char *function, const char *arg, int retc)
{ {
static char func[64]; static char func[64];
snprintf(func, 64, "conky_%s", function); snprintf(func, 64, "conky_%s", function);
@ -223,8 +224,10 @@ char *llua_do_read_call(const char *function, const char *arg, int retc)
return func; return func;
} }
#endif
char *llua_getstring(const char *args) /* call a function with args, and return a string from it (must be free'd) */
static char *llua_getstring(const char *args)
{ {
char *func; char *func;
char *ret = NULL; char *ret = NULL;
@ -244,7 +247,9 @@ char *llua_getstring(const char *args)
return ret; return ret;
} }
char *llua_getstring_read(const char *function, const char *arg) #if 0
/* call a function with args, and return a string from it (must be free'd) */
static char *llua_getstring_read(const char *function, const char *arg)
{ {
char *func; char *func;
char *ret = NULL; char *ret = NULL;
@ -263,8 +268,10 @@ char *llua_getstring_read(const char *function, const char *arg)
return ret; return ret;
} }
#endif
int llua_getnumber(const char *args, double *ret) /* call a function with args, and put the result in ret */
static int llua_getnumber(const char *args, double *ret)
{ {
char *func; char *func;
@ -521,3 +528,59 @@ void llua_update_info(struct information *i, double u_interval)
lua_setglobal(lua_L, "conky_info"); lua_setglobal(lua_L, "conky_info");
} }
void print_lua(struct text_object *obj, char *p, int p_max_size)
{
char *str = llua_getstring(obj->data.s);
if (str) {
snprintf(p, p_max_size, "%s", str);
free(str);
}
}
void print_lua_parse(struct text_object *obj, char *p, int p_max_size)
{
char *str = llua_getstring(obj->data.s);
if (str) {
evaluate(str, p, p_max_size);
free(str);
}
}
void print_lua_bar(struct text_object *obj, char *p, int p_max_size)
{
double per;
if (llua_getnumber(obj->data.s, &per)) {
#ifdef X11
if(output_methods & TO_X) {
new_bar(obj, p, (per/100.0 * 255));
} else
#endif /* X11 */
new_bar_in_shell(obj, p, p_max_size, per);
}
}
#ifdef X11
void print_lua_graph(struct text_object *obj, char *p, int p_max_size)
{
double per;
if (!p_max_size)
return;
if (llua_getnumber(obj->data.s, &per)) {
new_graph(obj, p, per);
}
}
void print_lua_gauge(struct text_object *obj, char *p, int p_max_size)
{
double per;
if (!p_max_size)
return;
if (llua_getnumber(obj->data.s, &per)) {
new_gauge(obj, p, (per/100.0 * 255));
}
}
#endif /* X11 */

View File

@ -38,12 +38,6 @@
/* load a lua script */ /* load a lua script */
void llua_load(const char *script); void llua_load(const char *script);
/* call a function with args, and return a string from it (must be free'd) */
char *llua_getstring(const char *args);
/* call a function with args, and return a string from it (must be free'd) */
char *llua_getstring_read(const char *function, const char *arg);
/* call a function with args, and put the result in ret */
int llua_getnumber(const char *args, double *ret);
/* close lua stuff */ /* close lua stuff */
void llua_close(void); void llua_close(void);
#ifdef HAVE_SYS_INOTIFY_H #ifdef HAVE_SYS_INOTIFY_H
@ -71,4 +65,12 @@ void llua_update_window_table(int text_start_x, int text_start_y, int text_width
void llua_setup_info(struct information *i, double u_interval); void llua_setup_info(struct information *i, double u_interval);
void llua_update_info(struct information *i, double u_interval); void llua_update_info(struct information *i, double u_interval);
void print_lua(struct text_object *, char *, int);
void print_lua_parse(struct text_object *, char *, int);
void print_lua_bar(struct text_object *, char *, int);
#ifdef X11
void print_lua_graph(struct text_object *, char *, int);
void print_lua_gauge(struct text_object *, char *, int);
#endif /* X11 */
#endif /* LUA_H_*/ #endif /* LUA_H_*/