On 17.10.2012 23:52, Manuel Kasser wrote:
> Am 17.10.2012 22:38, schrieb Uli Schlachter:
>> Well, it would help a lot if you would tell us which error you get. Because 
>> your
>> code looks fine to me.
> Oh, sorry, I forgot, because I do not get an error at all. I just have
> no CPU monitor anymore.
> 
> I made it work just by changing "cputxt = widgetfile.makecpuw" to
> "cputxt = widgetfile.makecpuw()", inspired by you (probably routinely)
> writing the function calls *with* brackets.
>
> Therefore: Thanks a lot!

Oh, whoops. I totally missed that. :-)

> Do I usually call functions with brackets, but when I want to bind them
> to key- or mousebinds, then I just give the name of the function and
> awesome calls them itself (with brackets(?)) when triggered? Because in
> the keybind-section I always place the fuction calls without brackets,
> otherwise I get a crash of my configuration.
> As you can see, I'm still a little bit inexperienced, sorry for the
> circumstances.

Functions are "normal values" in lua. So you can give a function as an argument
to another function. This is what the keybinding need: Their argument is a
function which should be called when the right keys are pressed. When you give
them foo() instead, foo() is called when awesome starts and the result is passed
to the keybinding and is used when the keys are pressed (if this result actually
is a function, which is unlikely...)

> However, for the purpose of experimenting and learning, I adapted the
> code, the ~/.config/awesome/widgetfile.lua is now:
>> function makecpuw()
>>     cputxt = widget({type = "textbox"})
>>     vicious.register(cputxt, vicious.widgets.cpu, '<span
> color="#9393cc">CPU: $1%</span>', 1)
>>     return cputxt
>> end
> 
> The rc.lua is adapted by changing "required("widgetfile")" to
> "dofile("/home/me/.config/awesome/widgetfile.lua")" and the line where I
> put the widget into "cputxt" to
>> cputxt = makecpuw()
> 
> That's how it should be? At least, it's working this way, however, I
> have to use the absolute path in the dofile-command, I can't use just
> the file name nor "./filename", not even "~/.config/awesome/filename" (I
> guess "~" is a thing just for the shell).

Hm, true. require() has a search path while dofile() wants the full path. At
least you could use:

  awful.util.getdir("config") .. "/filename"

("config" is the directory containing your rc.lua)

> And what's the exact difference between a module/required-command and a
> dofile-command? And a dofile-file is treated as being part of the rc.lua
> itself?

Yeah, dofile() "pretends" that the file is just included at the place you call
it. require() does more magic (e.g. making sure that the file is only included
once, even when require()'ing it multiple times). module("foo") does some weird
magic to place everything that follows under "foo.<here>". However, with lua 5.2
module() was deprecated. :-)

For more information:
http://www.lua.org/pil/8.1.html

Cheers,
Uli
-- 
"Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?" -- A. P. J.

-- 
To unsubscribe, send mail to [email protected].

Reply via email to