lua-users home
lua-l archive

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


On 9 July 2012 00:34, Laurent FAILLIE <l_faillie@yahoo.com> wrote:
> 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

It seems to me like arguments 2 and 3 have been swapped. Probably so
that if you use an anonymous function it can span multiple lines
without hiding the trailing number.