2

我正在尝试向我现有的 conky 设置添加一些 lua 功能,以便可以清理我的 conky 文本中的重复“代码”。例如,我有每个已安装的 FS、每个核心等的信息,其中我的面板中显示的每一行仅相差一个参数。

我的第一个骨架,尝试为此使用 lua 函数似乎可以运行,但在我的面板中没有显示任何内容。我只找到了非常简单的示例来以此为基础,所以我可能犯了一个简单的错误,但我什至不知道如何诊断它。我这里的代码是根据我已经找到的关于编写函数的内容建模的,例如如何在 Conky 中实现基本的 Lua 函数?,但这就是我在该主题上找到的所有深度,除了绘图和开罗示例。

这是添加到我的 conky 配置中的代码,以及我的 functions.lua 文件的内容

conky.config = {
...
    lua_load = '/home/conky-manager/MyConky/functions.lua',

};

conky.text = [[
...
${voffset 5}${lua conky_test 'test'}
...
]]

文件-functions.lua

function conky_test(parm1)
    return 'result text'
end

我希望看到的是“结果文本”显示在我的面板中该函数调用出现的位置,但没有显示。

是否有 conky 在运行时创建的日志,或者提供一些调试输出的方法?即使我在这里犯了一个简单的错误,我仍然希望能够在我的代码变得更加复杂时进行诊断。

4

2 回答 2

2

成功!

在将几篇文章的信息拼凑在一起后,我发现了我的基本缺陷 - 1. 缺少一个“conky_main”函数,2.缺少一个“lua_draw_hook_post”来调用它,3.意识到如果我从终端调用 conky,打印语句在lua中会出现在那里。

因此,对于任何看到这个问题并有同样问题的人,这里是更正的代码。

conky.config = {
...
    lua_load = '/home/conky-manager/MyConky/functions.lua',
    lua_draw_hook_post = "main",

};

conky.text = [[
...
${lua conky_test 'test'}
...
]]

以及我的functions.lua文件中的正确基础

function conky_test(parm1)
    return 'result text'
end

function conky_main()
    if conky_window == nil then
        return
    end
end

几点注意事项:

  1. 我还没有确定使用 'lua_draw_hook_pre' 代替 'lua_draw_hook_post' 是否有任何区别,但在这个例子中似乎没有。
  2. Also, some examples showed actually calling this 'test' function instead of writing a 'main', but the 'main' seemed to have value in checking to see if conky_window existed.
  3. Some examples seemed to state that naming functions with the prefix 'conky_' was required, but then showed examples of calling those functions without the prefix, so I assume the prefix is inferred during the call.
于 2019-01-15T02:32:46.690 回答
0

a major note: you should run conky from the directory containing the lua scripts.

于 2021-03-08T15:57:02.267 回答