Re: New Plugin: lua-graph

[email protected]
Newsgroups gmane.comp.desktop.xfce.goodies.devel
Organization orditech
Message-ID <[email protected]>
On Mon, 19 Dec 2005 21:54:37 +0200
"A. Gordon" <[email protected]> wrote:

> 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.
> 
Waw, that's not bad at all ;).

> 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.
> 
Hmm, very technical, yes. Lots of us use xfce4-dev-tools for that kind of things. 
Perhaps having a look at the other plugins can help.
Also, it makes me asking one thing: does your plugin work with the 4.2.x version of the panel?
Because some things have changed since for the upcoming 4.4 version of the panel. (but don't worry, the port 
is not very hard to do).
> If anyone is interested in this plugin, I'll be happy to send it, or 
> upload it to the Xfce-Goodies project.
> 
For Sure, you're welcome. Just get an account on berlios and then the projects leaders can add you to the project.

> 
> Gordon.

Bountykiller.

Ps: Since I'm currently rewritting a little the site in order to add some sections, I'll be happy to post a news
to wish you welcome. No objections?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.