You are not logged in.

#1 2017-02-05 21:07:53

alogim
Member
Registered: 2015-08-25
Posts: 43

Unable to make work Conky and Lua

I was following this tutorial.

I created a simple file called conky.conf with the following content:

--this is a lua script for use in conky
require 'cairo'

function conky_main()
    if conky_window == nil then
        return
    end
    local cs = cairo_xlib_surface_create(conky_window.display,
                                         conky_window.drawable,
                                         conky_window.visual,
                                         conky_window.width,
                                         conky_window.height)
    cr = cairo_create(cs)
    local updates=tonumber(conky_parse('${updates}'))
    if updates>5 then
        print ("hello world")
    end
    cairo_destroy(cr)
    cairo_surface_destroy(cs)
    cr=nil
end

When I run conky I get the following:

» ~  conky
conky: /home/michael/.config/conky/conky.conf:2: module 'cairo' not found:
        no field package.preload['cairo']
        no file './cairo.lua'
        no file '/usr/share/lua/5.1/cairo.lua'
        no file '/usr/share/lua/5.1/cairo/init.lua'
        no file '/usr/lib/lua/5.1/cairo.lua'
        no file '/usr/lib/lua/5.1/cairo/init.lua'
        no file './cairo.so'
        no file '/usr/lib/lua/5.1/cairo.so'
        no file '/usr/lib/lua/5.1/loadall.so'
» ~  

Note that I have conky-lua-archers.

Lua version is:

» ~  lua -v
Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio

Conky information:

» ~  conky -v
conky 1.10.6_pre compiled Sun  5 Feb 22:05:21 CET 2017 for Linux 4.9.6-1-ARCH x86_64

Compiled in features:

System config file: /etc/conky/conky.conf
Package library path: /usr/lib/conky


 General:
  * math
  * hddtemp
  * portmon
  * IPv6
  * Curl
  * wireless
  * nvidia
  * builtin default configuration
  * old configuration syntax
  * Imlib2
  * apcupsd
  * iostats
  * ncurses
  * Internationalization support
  * PulseAudio

 Lua bindings:
  * Cairo
  * Imlib2
  * RSVG
 X11:
  * Xdamage extension
  * Xinerama extension (virtual display)
  * XDBE (double buffer extension)
  * Xft
  * ARGB visual
  * Own window

 Default values:
  * Netdevice: enp7s4
  * Local configfile: $HOME/.conkyrc
  * Localedir: /usr/share/locale
  * Maximum netdevices: 64
  * Maximum text size: 16384
  * Size text buffer: 256

Last edited by alogim (2017-02-05 21:09:14)

Offline

#2 2017-02-05 22:57:15

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Unable to make work Conky and Lua

is it case sensitive? does changing it to require 'Cairo' fix it?

Offline

#3 2017-02-05 23:28:13

alogim
Member
Registered: 2015-08-25
Posts: 43

Re: Unable to make work Conky and Lua

No, it does not fix it.

Is there a guide out there to properly install conky and properly install lua for ArchLinux? I really can not figure out what is wrong.

Offline

#4 2017-02-06 11:23:07

rtoijala
Member
Registered: 2011-09-11
Posts: 36

Re: Unable to make work Conky and Lua

a) The conky package does not support drawing with cairo. Since your conky shows that it supports cairo, I assume you are using conky-cairo from the AUR.

b) Your conky.conf should contain the config for conky, not the lua script. An example conky.conf is here:

conky.config = {
	lua_load = '/full/path/to/script.lua',
	lua_draw_hook_pre = 'conky_main',
	update_interval = 1.0,
	out_to_x = true,
};

conky.text = ""

c)  Your lua script should be in an external file, the full path of which is given to lua_load in conky.conf.
As an example, the following lua script should show whether everything works:

--this is a lua script for use in conky
require 'cairo'

function conky_main()
	io.stderr:write('here')
    if conky_window == nil then
        return
    end
    local cs = cairo_xlib_surface_create(conky_window.display,
                                         conky_window.drawable,
                                         conky_window.visual,
                                         conky_window.width,
                                         conky_window.height)
    cr = cairo_create(cs)
    local updates=tonumber(conky_parse('${updates}'))
    font="Mono"
    font_size=16
    text="hello world " .. tostring(updates)
    xpos,ypos=100+updates*17,100+updates*17
    red,green,blue,alpha=1,1,1,1
    font_slant=CAIRO_FONT_SLANT_NORMAL
    font_face=CAIRO_FONT_WEIGHT_NORMAL
    cairo_select_font_face (cr, font, font_slant, font_face);
    cairo_set_font_size (cr, font_size)
    cairo_set_source_rgba (cr,red,green,blue,alpha)
    cairo_move_to (cr,xpos,ypos)
    cairo_show_text (cr,text)
    cairo_stroke (cr)
    cairo_destroy(cr)
    cairo_surface_destroy(cs)
    cr=nil
end

It simply draws a changing text to the screen, moving a bit to the right and down every time.

Running with conky -c conky.conf from the dir where conky.conf and script.lua are located draws the text to the root window on my system.

Offline

Board footer

Powered by FluxBB