lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

Continuing to explore LGI possibilities, I'm facing issues when I'm trying to use timeout_add_seconds().

My reference is : developer.gnome.org/glib/2.30/glib-The-Main-Event-Loop.html#g-timeout-add-seconds which said this function requires 3 arguments.

So my code is :

local lgi = require 'lgi'
local GLib = lgi.GLib

cnt = 0

function tictac()
    cnt = cnt + 1
    print("tic")
end

GLib.timeout_add_seconds( 2, tictac, 0)

while true do
    GLib.usleep(1000000)    -- wait 1 second
    print( cnt )
end

But when I launch it, I got following error :

$ lua timer.lua
lua: timer.lua:24: bad argument #3 to 'timeout_add_seconds' (number expected, got function)
stack traceback:
    [C]: in function 'timeout_add_seconds'
    timer.lua:24: in main chunk
    [C]: ?

So where I'm wrong ?

Bye

Laurent