0

I can not display the value of the string in conky, tell me where the errors are.

my function call: ${lua conky_func}

conky.config section: lua_load = '/home/user/.conky/function.lua',

result: conky: llua_getstring: function conky_func didn't return a string, result discarded

$ lua
Lua 5.3.6  Copyright (C) 1994-2020 Lua.org, PUC-Rio
> function conky_func()
result = os.execute("ps aux | awk '{sum+=$6} END {print sum/1024}'; exit")
return result
end 
> conky_func()
4902.65
true
> ^C

Where are the errors, please help.

meuh
  • 11,500
  • 2
  • 29
  • 45
igor
  • 1
  • 1

1 Answers1

0

The variable result appears to be a floating point number rather than a string. I haven't tested it, but I'd try changing return result to return string.format("%f2", result). See 6.4 – String Manipulation in the Lua Reference Manual and documentation on sprintf in the C reference section of cppreference.com for more information.

David Yockey
  • 595
  • 3
  • 11
  • conky: llua_do_call: function conky_func execution failed: /home/dell/.conky/function.lua:3: bad argument #2 to 'format' (number expected, got boolean) 4082.64 – igor Feb 21 '23 at 19:53
  • Unfortunately, I think that AWK needs to be rewritten ?? thanks David – igor Feb 21 '23 at 20:01
  • My mistake... `os.execute` returns **true** if the command passed to the shell terminates successfully, so _of course_ `result` is a boolean. The problem seems to actually be in how to get the AWK result back into Lua from the shell. Maybe write the AWK result to an environment variable and then read it in using `os.getenv` or write it to a file and read it in using `io.open` and `file:read`. – David Yockey Feb 22 '23 at 00:20
  • good idea, I'll try it.. thanks, I also think that AWK should not be used like that. – igor Feb 22 '23 at 17:12