1

I'm working to streamline my conky by refactoring display logic into lua functions, but I can't find any examples of how to pass file paths, and my attempts at guessing are yielding script errors.

What I am attempting to to do is display the following things about each fs on my panel: root, home and 3 other mounted filesystems. The current, working conky logic for each row is similar to this line for /home:

    ${goto 10}${voffset 4}${font StyleBats:size=8}4${font}   Home: ${goto 90}${color1}${fs_bar 6,100 /home}${color} ${goto 150}${alignr}${fs_free /home}

Each subsequent line differs ONLY in the label and the 2 hardcoded paths (in the fs_bar and fs_free sections)

So, I'm shooting for a function call like this:

    ${lua conky_display_fs("Home", "/home")}

with a lua function:

    function conky_display_fs (fname, fpath)
    local outstring = conky_parse("${goto 10}${voffset 4}${font StyleBats:size=8}4${font}   " .. fname .. ": ${goto 90}${color1}${fs_bar 6,100 " .. fpath .. "}${color} ${goto 150}${alignr}${fs_free " .. fpath .."}")

    print (outstring)
    return outstring

end

but it consistently fails showing the following in the conky debug log

    conky: llua_do_call: function conky_display_fs("Home", execution failed: attempt to call a nil value

SO, I'm guessing the issue is in HOW I pass the path string, since it only shows the first value in the error. I thought of string escaping, etc, but file names used in other parts of the conky config do not require any, such as:

    lua_load = "~/conky-manager/MyConky/functions.lua",

and I can't find any examples of passing file paths, or even passing multiple string parameters, only simple examples using vars.

This is for an existing conky config, where the successful conky text shown in the first code block works perfectly. I've already tried several variations on the call, changing quoting, comma/no comma, different parameter name to avoid keywords...

bregia
  • 83
  • 8

1 Answers1

2

Solved this after about 20 different experiments. The answer is that, in spite of wanting strings quoted in the config section, including lua config, they ARE NOT to be quoted in lua calls. Additionally, I removed the parens.

So, the right way to call a lua function with strings is as follows:

  ${lua conky_display_fs Home, /home}  
bregia
  • 83
  • 8