From 33754ecebe33eb0b5f517012da59757a3207cb52 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 6 Jun 2009 17:25:34 -0600 Subject: [PATCH] Let lua_graph behave more like other graphs. Changed llua_getinteger() to llua_getnumber() returning a double, so that you can use floating point values in graphs etc. Lua graph will scale like other graphs (except execgraph) by default now, and you can manually set a scale with the scale argument. --- doc/variables.xml | 3 +-- src/conky.c | 10 +++++----- src/llua.c | 6 +++--- src/llua.h | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index c0a318d..fc84de0 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -1782,8 +1782,7 @@ function_name (function parameters) Executes a Lua function with given parameters and - draws a graph. Expects result value to be an integer - between 0 and 100. See also 'lua_load' on how to load + draws a graph. Expects result value to be any number, and by default will scale to show the full range. See also 'lua_load' on how to load scripts. Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and diff --git a/src/conky.c b/src/conky.c index 5695a68..23621cb 100644 --- a/src/conky.c +++ b/src/conky.c @@ -4073,7 +4073,7 @@ static void generate_text_internal(char *p, int p_max_size, read_exec(cmd, p, text_buffer_size); barnum = get_barnum(p); - if (barnum >= 0.0) { + if (barnum > 0) { new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum), 100, 1, showaslog, tempgrad); } @@ -4515,7 +4515,7 @@ static void generate_text_internal(char *p, int p_max_size, } OBJ(lua_bar) { int per; - if (llua_getinteger(obj->data.s, &per)) { + if (llua_getnumber(obj->data.s, &per)) { #ifdef X11 if(output_methods & TO_X) { new_bar(p, obj->a, obj->b, (per/100.0 * 255)); @@ -4531,14 +4531,14 @@ static void generate_text_internal(char *p, int p_max_size, #ifdef X11 OBJ(lua_graph) { int per; - if (llua_getinteger(obj->data.s, &per)) { + if (llua_getnumber(obj->data.s, &per)) { new_graph(p, obj->a, obj->b, obj->c, obj->d, - (per/100.0 * 255), 100, 1, obj->char_a, obj->char_b); + per, obj->e, 1, obj->char_a, obj->char_b); } } OBJ(lua_gauge) { int per; - if (llua_getinteger(obj->data.s, &per)) { + if (llua_getnumber(obj->data.s, &per)) { new_gauge(p, obj->a, obj->b, (per/100.0 * 255)); } } diff --git a/src/llua.c b/src/llua.c index 4a0953f..56aa953 100644 --- a/src/llua.c +++ b/src/llua.c @@ -165,7 +165,7 @@ char *llua_getstring_read(const char *function, const char *arg) return ret; } -int llua_getinteger(const char *args, int *per) +double llua_getnumber(const char *args, int *per) { char *func; @@ -174,9 +174,9 @@ int llua_getinteger(const char *args, int *per) func = llua_do_call(args, 1); if(func) { if(!lua_isnumber(lua_L, -1)) { - ERR("llua_getinteger: function %s didn't return an integer, result discarded", func); + ERR("llua_getnumber: function %s didn't return a number, result discarded", func); } else { - *per = lua_tointeger(lua_L, -1); + *per = lua_tonumber(lua_L, -1); lua_pop(lua_L, 1); return 1; } diff --git a/src/llua.h b/src/llua.h index 9f920f4..80179f5 100644 --- a/src/llua.h +++ b/src/llua.h @@ -30,7 +30,7 @@ void llua_init(void); void llua_load(const char *script); char *llua_getstring(const char *args); char *llua_getstring_read(const char *function, const char *arg); -int llua_getinteger(const char *args, int *per); +double llua_getnumber(const char *args, int *per); void llua_close(void); #ifdef HAVE_SYS_INOTIFY_H void llua_inotify_query(int wd, int mask); -- 1.7.9.5