debugging - How to implement a basic Lua function in Conky? -


i trying add function conky prints length of string debug purposes. code, inside file called test.lua, pretty trivial:

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

...and load this. in conky.config section have:

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

...in conky.text section have:

${lua test "fooo"} 

...where test name of function , fooo string test.

the expected result should printed 4 in conky, instead of get:

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

i have browsed through documentation, can't find anything. know failure is?

several guidances on how implement functions in conky:

  • first of all: must use conky_ before function's name. otherwise, following error when running conky:

    attempt call nil value 
  • secondly: must return value. don't mind repeating - crucial. otherwise, get:

    function foobar didn't return string, result discarded function_result 

    ...in terminal, , conky left empty of values related code. nothing printed regarding function.

  • last not least: must call function like:

    lua_load = '/path/to/function.lua', -- whatever content... ${lua function_name function_parameter1 function_parametern} -- in case use more 1 parameter. 

in summary, dummy function template be:

  • main file (conky.conf):

    conky.config = {     -- whatever content... lua styled comments.     lua_load = '/path/to/function.lua', }  conky.text = [[     # whatever content... in section comments started '#'!         ${lua function_name parameter} ]] 
  • function file:

    function conky_function_name(parameter)     -- whatever content... remember lua, not conky.text syntax. use '--' comments!     return whatever -- no return, no party. function must return something! end 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -