functiondebuggingluacustomizationconky

How to implement a basic Lua function in Conky?


I am trying to add a function to my Conky which prints the length of a string for debug purposes. The code, inside a file called test.lua, is pretty trivial:

function test(word)
return string.len(word)
end

...and I load it like this. In my conky.config section I have:

lua_load = '/home/xvlaze/test.lua',
lua_draw_hook_pre = 'test'

...in the conky.text section I have:

${lua test "fooo"}

...where test is the name of the function and fooo the string to test.

The expected result should be a printed 4 in Conky, but instead of that I get:

conky: llua_do_call: function conky_test execution failed: /home/xvlaze/test.lua:2: attempt to index a nil value (local 'string')
conky: llua_getstring: function conky_test didn't return a string, result discarded

I have browsed through the documentation, but I can't find anything. Does anybody know where the failure is?


Solution

  • Several guidances on how to implement functions in Conky:

    In summary, a dummy function template could be: