Lua (original) (raw)

APIs

APIs are functions you can call in your Lua scripts to interact with Conky. See man -P "less -p 'LUA API'" conky for a complete list of Conky Lua APIs.

Information

Since 1.7.1, Conky features built-in Lua support. Lua is a "lightweight, reflective, imperative and functional programming language, designed as a scripting language with extensible semantics as a primary goal" which makes it ideal for integration into Conky. Together with the Cairo, RSVG and Imlib2 libraries (use build flags: BUILD_LUA_CAIRO, BUILD_LUA_RSVG,BUILD_LUA_IMLIB2) this allows for almost infinite possibilities. You can draw whatever you want, implement your own graphs, process data, ... To check if your conky installations supports these Lua libraries use conky -v. You can use any variable from conky within Lua but you can also pass them to a Lua function when you call it in conky.

conky.config = { lua_load = '~/.conky/Test/cpu_graph.lua', lua_draw_hook_pre = 'main_graph', };

This will load the Lua file cpu_graph.lua and call the Lua functionconky_main_graph before it updates the text section of the config. For safety all the functions you want to be callable from within conky must start withconky_ this prefix must not be added when calling your Lua function from your conky configuration (see the example). You can load multiple scripts separated by spaces.

You can load multiple scripts, just make sure the conky_ functions within the Lua scripts have a unique name. Do you want to get started? See Lua Tutorial.

Tips and Tricks

-- Setup Global Variables if tonumber(conky_parse('${updates}')) < 2 then --# don't reset these global variables when changes are made to the lua script -- initialize previous epoch (use to prevent graph tables from being -- screwed up when other windows are moved across the conky window) previousEpoch = os.time() end

function conky_main() --# main function controls everything else local newEpoch = os.time()

if previousEpoch < newEpoch then
    -- "Collect Data in Global Variables Here"
end
if previousEpoch < newEpoch then
    previousEpoch = newEpoch
else
    print("Error: epoch check warning old:" .. previousEpoch .. " new:" .. newEpoch)
end

end

Sites

Add a custom footer