1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2009 Toni Spets
10 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 lua_State *lua_L = NULL;
40 void llua_load(const char *script)
43 error = luaL_loadfile(lua_L, script);
45 ERR("llua_load: %s\n", lua_tostring(lua_L, -1));
48 lua_pcall(lua_L, 0, 0, 0);
52 char *llua_getstring(const char *args)
55 char *tmp = strdup(args);
59 if(!lua_L) return NULL;
61 char *ptr = strtok(tmp, " ");
62 if(!ptr) return NULL; /* function name missing */
63 snprintf(func, 64, "conky_%s", ptr);
65 lua_getglobal(lua_L, func);
67 ptr = strtok(NULL, " ");
69 lua_pushstring(lua_L, ptr);
70 ptr = strtok(NULL, " ");
74 if(lua_pcall(lua_L, parcount, 1, 0) != 0) {
75 ERR("llua_getstring: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1));
78 if(!lua_isstring(lua_L, -1)) {
79 ERR("llua_getstring: function %s didn't return a string, result discarded\n", func);
81 ret = strdup((char *)lua_tostring(lua_L, -1));
91 int llua_getpercent(const char *args, int *per)
94 char *tmp = strdup(args);
99 char *ptr = strtok(tmp, " ");
100 if(!ptr) return 0; /* function name missing */
101 snprintf(func, 64, "conky_%s", ptr);
103 lua_getglobal(lua_L, func);
105 ptr = strtok(NULL, " ");
107 lua_pushstring(lua_L, ptr);
108 ptr = strtok(NULL, " ");
113 if(lua_pcall(lua_L, parcount, 1, 0) != 0) {
114 ERR("llua_getpercent: function %s execution failed: %s\n", func, lua_tostring(lua_L, -1));
117 if(!lua_isnumber(lua_L, -1)) {
118 ERR("llua_getpercent: function %s didn't return a number (percent), result discarded\n", func);
120 *per = lua_tonumber(lua_L, -1);