fi
dnl
+dnl Lua
+dnl
+
+AC_ARG_ENABLE([lua],
+ AC_HELP_STRING([--enable-lua], [enable if you want Lua scripting support @<:@default=no@:>@]),
+ [want_lua="$enableval"], [want_lua=no])
+#
+AM_CONDITIONAL(BUILD_LUA, test x$want_lua = xyes)
+if test x$want_lua = xyes; then
+ PKG_CHECK_MODULES(LUA, lua >= 5.1, [ ],[
+ PKG_CHECK_MODULES(LUA51, lua5.1 >= 5.1, [ ])
+ ])
+ CFLAGS="$CFLAGS $LUA_CFLAGS $LUA51_CFLAGS"
+ LIBS="$LIBS $LUA_LIBS $LUA51_LIBS"
+ AC_DEFINE(HAVE_LUA, 1, [Define if you want Lua scripting support])
+fi
+
+dnl
dnl Wireless extensions
dnl
hddtemp: $want_hddtemp
portmon: $want_portmon
RSS: $want_rss
+ Lua: $want_lua
wireless: $want_wlan
IBM: $want_ibm
nvidia: $want_nvidia
#ifdef RSS
" * RSS\n"
#endif /* RSS */
+#ifdef HAVE_LUA
+ " * Lua\n"
+#endif /* HAVE_LUA */
#ifdef HAVE_IWLIB
" * wireless\n"
#endif /* HAVE_IWLIB */
free(data.rss.action);
break;
#endif
+#ifdef HAVE_LUA
+ case OBJ_lua:
+ llua_close();
+ break;
+ case OBJ_lua_bar:
+ llua_close();
+ break;
+#endif
case OBJ_pre_exec:
break;
#ifndef __OpenBSD__
"[act_par] [spaces in front]");
}
#endif
+#ifdef HAVE_LUA
+ END OBJ(lua, 0)
+ if(arg) {
+ obj->data.s = strndup(arg, text_buffer_size);
+ } else {
+ CRIT_ERR("lua needs arguments: <function name> [function parameters]");
+ }
+
+#ifdef X11
+ END OBJ(lua_bar, 0)
+ if(arg) {
+ arg = scan_bar(arg, &obj->a, &obj->b);
+ if(arg) {
+ obj->data.s = strndup(arg, text_buffer_size);
+ } else {
+ CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
+ }
+ } else {
+ CRIT_ERR("lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
+ }
+#endif
+#endif
#ifdef HDDTEMP
END OBJ(hddtemp, 0)
if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
}
}
#endif
+#ifdef HAVE_LUA
+ OBJ(lua) {
+ char *str = llua_getstring(obj->data.s);
+ if(str) {
+ snprintf(p, p_max_size, "%s", str);
+ free(str);
+ }
+ }
+
+#ifdef X11
+ OBJ(lua_bar) {
+ int per;
+ if(llua_getpercent(strdup(obj->data.s), &per)) {
+ new_bar(p, obj->a, obj->b, (per/100.0 * 255));
+ }
+ }
+#endif
+#endif
#ifdef HDDTEMP
OBJ(hddtemp) {
char *endptr, unit;
CONF_ERR;
}
}
+#ifdef HAVE_LUA
+ CONF("lua_load") {
+ llua_init();
+ if(value) {
+ char *ptr = strtok(value, " ");
+ while(ptr) {
+ llua_load(ptr);
+ ptr = strtok(NULL, " ");
+ }
+ } else {
+ CONF_ERR;
+ }
+ }
+#endif
CONF("color0"){}
CONF("color1"){}
--- /dev/null
+/* Conky, a system monitor, based on torsmo
+ *
+ * Any original torsmo code is licensed under the BSD license
+ *
+ * All code written since the fork of torsmo is licensed under the GPL
+ *
+ * Please see COPYING for details
+ *
+ * Copyright (c) 2007 Toni Spets
+ * 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"
+
+lua_State *lua_L = NULL;
+
+void llua_init()
+{
+ if(lua_L) return;
+ lua_L = lua_open();
+ luaL_openlibs(lua_L);
+}
+
+void llua_load(const char *script)
+{
+ int error;
+ error = luaL_loadfile(lua_L, script);
+ if(error) {
+ fprintf(stderr, "llua_load: %s\n", lua_tostring(lua_L, -1));
+ lua_pop(lua_L, 1);
+ } else {
+ lua_pcall(lua_L, 0, 0, 0);
+ }
+}
+
+char *llua_getstring(const char *args)
+{
+ char *ret = NULL;
+ char *tmp = strdup(args);
+ char func[64];
+ int parcount = 0;
+
+ if(!lua_L) return NULL;
+
+ char *ptr = strtok(tmp, " ");
+ if(!ptr) return NULL; /* function name missing */
+ snprintf(func, 64, "conky_%s", ptr);
+
+ lua_getglobal(lua_L, func);
+
+ ptr = strtok(NULL, " ");
+ while(ptr) {
+ lua_pushstring(lua_L, ptr);
+ ptr = strtok(NULL, " ");
+ parcount++;
+ }
+
+ if(lua_pcall(lua_L, parcount, 1, 0) != 0) {
+ fprintf(stderr, "llua: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1));
+ lua_pop(lua_L, -1);
+ } else {
+ if(!lua_isstring(lua_L, -1)) {
+ fprintf(stderr, "llua: function %s didn't return a string, result discarded\n", func);
+ } else {
+ ret = strdup((char *)lua_tostring(lua_L, -1));
+ lua_pop(lua_L, 1);
+ }
+ }
+
+ free(tmp);
+
+ return ret;
+}
+
+int llua_getpercent(const char *args, int *per)
+{
+ char func[64];
+ char *tmp = strdup(args);
+ int parcount = 0;
+
+ if(!lua_L) return 0;
+
+ char *ptr = strtok(tmp, " ");
+ if(!ptr) return 0; /* function name missing */
+ snprintf(func, 64, "conky_%s", ptr);
+
+ lua_getglobal(lua_L, func);
+
+ ptr = strtok(NULL, " ");
+ while(ptr) {
+ lua_pushstring(lua_L, ptr);
+ ptr = strtok(NULL, " ");
+ parcount++;
+ }
+ free(tmp);
+
+ if(lua_pcall(lua_L, parcount, 1, 0) != 0) {
+ fprintf(stderr, "llua: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1));
+ lua_pop(lua_L, -1);
+ } else {
+ if(!lua_isnumber(lua_L, -1)) {
+ fprintf(stderr, "llua: function %s didn't return a number (percent), result discarded\n", func);
+ } else {
+ *per = lua_tonumber(lua_L, -1);
+ lua_pop(lua_L, 1);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void llua_close()
+{
+ if(!lua_L) return;
+ lua_close(lua_L);
+ lua_L = NULL;
+}