2

I'm trying to add some lua functionality to my existing conky setup so that repetitive "code" in my conky text can be cleaned up. For example, I have information for each mounted FS, each core, etc. where each row displayed in my panel differs ONLY by one parameter.

My first skeletal, attempt at using lua functions for this seems to run but displays nothing in my panel. I've only found very simple examples to base this on, so I may have made a simple error, but I don't even know how to diagnose it. My code here is modeled after what I HAVE been able to find regarding writing functions, such as this How to implement a basic Lua function in Conky? , but that's about all the depth I've found on the topic except for drawing and cairo examples.

Here's the code added to my conky config, as well as the contents of my functions.lua file

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

};

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

file - functions.lua

function conky_test(parm1)
    return 'result text'
end

What I would expect is to see is "result text" displayed in my panel at the location where that function call appears, but nothing shows.

Is there a log created by conky as it runs, or a way to provide some debug output? Even if I'd made a simple error here, I'd still like to have the ability to diagnose things as my code gets more complex.

bregia
  • 83
  • 8

2 Answers2

3

Success!

After cobbling info from several articles together, I figured out my basic flaws - 1. Missing a 'conky_main' function, 2. Missing a 'lua_draw_hook_post' to invoke it, and 3. Realizing that if I invoke conky from a terminal, print statements in lua would appear there.

So, for anyone who sees this question and has the same issues, here's the corrected code.

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

};

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

and the proper basics in my functions.lua file

function conky_test(parm1)
    return 'result text'
end

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

A few notes:

  1. I still haven't determined if using 'lua_draw_hook_pre' instead of 'lua_draw_hook_post' makes any difference, but it doesn't seem to in this example.
  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.
bregia
  • 83
  • 8
  • not working for me right now. Did things changes? – nyxee Mar 08 '21 at 05:56
  • I can't seem to get it working properly either. I always end up getting blank variables. I can't seem to print them to the terminal or anything either? – MostHated Mar 15 '21 at 01:20
  • Actually, I just did get it working now. It had to do with my overall setup. I was trying to make things modular in different files but I had been looking at several different projects on github and how they did it. Because of that, it was a bit mixed and matched. I got things straightened out and then having the 'lua_load = main.lua' (in my case) got it working straight away after that. Didn't need the lua_draw_hook or conky_main(). – MostHated Mar 15 '21 at 03:17
0

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

nyxee
  • 2,773
  • 26
  • 22