New Plugin: lua-graph
"A. Gordon" <[email protected]>
| Newsgroups | gmane.comp.desktop.xfce.goodies.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello,
(a bit of a long story, with a question at the end...)
I've written a new plugin, called Lua-Graph.
This plugin is a generic Lua-host plugin, which allows a Lua script to
set the plugin's content.
With this plugin, you have quick & dirty solution for monitoring any
kind of data on your computer, until a fully-fledged dedicated plugin is
available.
Explanation:
Lua (http://www.lua.org) is a light-weight programming language designed
for extending applications.
the Lua library is GPLed, ANSI compatible, very portable and easy to use.
Lua scripts for this plugin should have two functions:
"init" will be called when the plugin loads, and will create labels and
progress bars.
"update" will be called once every second, and will update the label's
text and the progress bar's value and colors.
First example: the following Lua-script makes the plugin monitor my
computer's temperature (temperature is displayed as a number on the Xfce
panel)
------begin temperature script -----
function init()
add_label("lbl", "0");
end
function update()
value =
read_numeric_value_from_file("/proc/acpi/thermal_zone/THM0/temperature","temperature");
set_label_text( "lbl", string.format("%d c",value))
end
------ end temperature script -----
As you can see, updating the text is very easy...
"add_label" and "set_label_text" are two plugin functions that create a
label on the Xfce-panel, and update the label's text.
Second Example:
Read Battery level and AC state (only later I found out there's an
'xfce-battery' plugin...)
------begin Battery script ------
function init()
add_label("lbl", "");
add_progressbar("prg",0,0,0);
max_bat_charge =
read_numeric_value_from_file("/proc/acpi/battery/BAT0/info","last full
capacity");
end
function update()
local current_charge =
read_numeric_value_from_file("/proc/acpi/battery/BAT0/state","remaining
capacity");
local ac = read_line_from_file("/proc/acpi/ac_adapter/AC/state");
local i = string.find(ac,"on");
local state = "<span background=\"#FF009D\">BAT</span>" ;
if i ~= nil then
state = "AC";
end;
percent = current_charge*100/max_bat_charge;
set_label_text( "lbl", state .. "\n" ..string.format("%d%%", percent)) ;
set_progress_bar_value( "prg", percent ) ;
set_progress_bar_color( "prg", get_status_color(percent) ) ;
end
----- end battery script -----
The above script read the AC status, and when I'm running on batteries,
displays "BAT" with a pinkish background.
It also displays the battery charge (as percentage), and a colored
progress bar.
And now, my (very technical) question:
In order to compile the plugin, I need the "Lua" shared library.
The "C" source uses
#include <lua50/lua.h>
#include <lua50/lualib.h>
and the linking phase requires
LDFLAGS += -llua50 -llualib50
It works on my computer (because I have the "lua-dev" installed, after I
manually added the "LDFLAGS" to the "Makefile").
But how do I make the "configure" script check for the existence of "Lua" ?
The whole gnu build process it a bit confusing... (automake, autoconf,
m4 ??)
I guess I should add "AC_CHECK_HEADER(lua50.h)" somewhere, but I don't
know where, and how to re-create everything (simply running "autoconf"
did not work).
Thank you for your help.
If anyone is interested in this plugin, I'll be happy to send it, or
upload it to the Xfce-Goodies project.
Gordon.