Closed ghost closed 6 years ago
Do you have an example config we can use to test this?
Certainly. Here are gutted but hopefully stil functional - apart from with respect to the problem at issue! - versions of my conky script and the lua script in question. (The originals are a bit large and involved.)
I edited the title of this bug report, to clear up a confusion I had introduced. To be clear: the problem is with the update field in the conky_info table.
Pastebin does not last long. I'm copying the config to here.
-- ______ __
-- / ____/___ ____ / /____ __
-- / / / __ \/ __ \/ //_/ / / /
-- / /___/ /_/ / / / / ,< / /_/ /
-- \____/\____/_/ /_/_/|_|\__, /
-- /____/
-- ///////////////////////
-- // CONFIGURATION //
-- ///////////////////////
conky.config =
{
update_interval = 1.1,
update_interval_on_battery = 1.25,
total_run_times = 0,
short_units = true,
format_human_readable = true,
own_window_type = "desktop",
own_window_hints = "undecorated,below,sticky,skip_taskbar,skip_pager",
own_window_transparent = false,
own_window_argb_visual = true,
own_window_argb_value = 3,
gap_x = 40,
gap_y = 10,
minimum_width = 2560,
maximum_width = 2560,
alignment = "top_left",
border_outer_margin = 3,
draw_graph_borders = true,
use_xft = true,
font = "Noto Sans:size=19",
draw_shades = false,
use_spacer = "left",
-- // LUA script(s) //
lua_load = '~/test.lua',
-- See inter alia: https://github.com/brndnmtthws/conky/wiki/Lua-API
}
-- ///////////////
-- // Main //
-- ///////////////
conky.text = [[
${lua_parse conky_test}\
]]
#!/usr/local/bin/lua
conkyTicks_toRunAtAll = 8
local rtnText = ''
-- MAIN
function conky_test ()
local ConkyTicks_current
-- Necessary check
if conky_window == nil then
return ''
end
-- Abort if system not been up (= time since boot?) for < X seconds.
-- Broken at present
if conky_info ['uptime'] < 21 then
return ''
end
ConkyTicks_current = tonumber( conky_parse ( "${updates}" ) )
if ( ( ConkyTicks_current % conkyTicks_toRunAtAll ) ~= 0 ) then
return rtnText
end
rtnText = 'test'
return rtnText
end
-- ##### EOF #####
OK. But I set the Pastebin's expiry on both scripts to six months.
Stupid question. Am I missing a second script? I only see one script.
My mistake. Something had gone wrong with the formatting in my post. I've fixed it and here too is a link to that same - previousy missing - lua script.
So far, I see duplicate maximum_width = 2560
. I see that it printed 0
for uptime
and 1.1
for update_interval
because you specified that in your config. Also, you may be interested in trying /usr/bin/env lua
so it can find lua
well on other machines.
@plikhari Can you see if he's doing Lua correctly?
@su8 Can you see if this is correct? It's only two lines in ~/src/lluaa.cc
.
./src/llua.cc:539: llua_set_number("uptime", i->uptime);
./src/llua.cc:555: llua_set_number("uptime", i->uptime);
EDIT: I hope we can close this issue today. :-)
uptime
has always printed 0
- but is this not the system Uptime - in which case it should match ${uptime}
variable. In LUA you can also derive this value using conky_parse('${uptime}')
update_interval
has always worked !!!
Here's the initialization of uptime
https://github.com/brndnmtthws/conky/blob/bbaa0e9ac8d8024245c2dde676ed4b6376f8300e/src/llua.cc#L539
Here's the initialization of the above function https://github.com/brndnmtthws/conky/blob/bbaa0e9ac8d8024245c2dde676ed4b6376f8300e/src/conky.cc#L3048
Even if we add this:
diff --git a/src/conky.cc b/src/conky.cc
index 52422ce5..09157b74 100644
--- a/src/conky.cc
+++ b/src/conky.cc
@@ -3045,6 +3045,7 @@ void initialisation(int argc, char **argv) {
#ifdef BUILD_X11
X11_create_window();
#endif /* BUILD_X11 */
+ update_uptime();
llua_setup_info(&info, active_update_interval());
/* Set signal handlers */
The uptime information will be updated only once :disappointed:
edit: and it will be the raw /proc/uptime
value.
Ahh so there you have it - if it is only going to update one time - we really have no use for it.
I have always seen conky_parse("${uptime}")
in use - so we can change the docs and remove the uptime
part.
Thanks, all. (What I really need, though, is time in seconds or milliseconds since either boot or resumption from sleep . .)
For that you can use the cat /proc/uptime
or uptime
- former gives 2 values - 1st is the uptime in seconds. in LUA you can use as I have suggested above - and convert those to seocnds
Thanks. Also, though, I do not understand the comment above about
/usr/bin/env
I think it'd be good idea to take out the whole conky_info
if it's going to require a sole option update_interval
to work. Maybe I don't see it, but is there a Lua function to parse conky settings like update_interval
, default_bar_width
, etc...?
For waking up...
$ journalctl -b | grep 'ACPI: Waking up' | tail -n1
Aug 14 04:23:29 z420 kernel: ACPI: Waking up from system sleep state S3
Change #!/usr/local/bin/lua
to #!/usr/bin/env lua
so it know where to find lua
.
I have /usr/bin/lua
here. Your lua
seems to be coming from non-distro installation.
EDIT: https://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html
hey that is a very critical option - please leave it as it is - update_interval
if you are running lua from within conky - then do not use environment statement on the first line !!!
@plikhari Why? #!/usr/local/bin/lua
should have higher precedence over #!/usr/bin/lua
either way.
i am not talking about any precedence - this line need not be used as the lua interpreter is triggered by lua_load = filename.lua
variable in the config section.
Well, on my computer anyway, conky can run lua files just fine, whether they start with (1)
#!/usr/local/bin/lua
or with what was suggested to me on this thread, viz., (2)
#!/usr/bin/env lua
And I've tested 1 (but not 2) on two other computers (all admittedly running the same Linux distribution, namely, Mint Cinnamon).
#!/usr/bin/env lua
will traverse the $PATH
to find any lua executables, it will stop the search on first occurrence, and is the preferred way to write portable scripts/programs.
If you are running lua scripts as stand alone and not within conky - then you need to use the environment shebang - otherwise - it is not the preferred way if the script is being run within conky + lua using lua_load.
This is also not required if you are going to run the script as for example lua ./luascript.lua
.
That line is not even looked at in conky + lua thing.
I just tested with #!/bin/bash
in a lua file and it still runs as lua file !
There is no other way to get update_interval
from within LUA other than conky_info
- and my lua_startup_hook
depends on that !!
lua ./luascript.lua
You are using the interpreter here, that's why it ignores the shebang.
Add #!/bin/bash
, chomd +x luascript.lua
and try running it by executing ./luascript.lua
I absolutely agree with your point.
My case only exists for conky and embedded lua - not for stand alone situations.
@lasers Maybe I don't see it, but is there a Lua function to parse conky settings like update_interval, default_bar_width, etc...?
@su8 Is it trivial to implement this? All conky settings, not just update_interval
.
This table entry appears to be blank - whereas the update_interval entry works. Apologies if some compile-time option is needed for this (which I have not enabled).
Linux Mint 19 Cinnamon x64.
conky 1.10.9_pre compiled Thu 9 Aug 22:06:55 BST 2018 for Linux 4.17.13-041713-generic x86_64
Compiled in features:
System config file: /etc/conky/conky.conf Package library path: /usr/local/lib/conky
General:
Own window
Music detection:
MOC
Default values: