lua-users home
lua-l archive

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


On 7/9/2012 12:24 PM, Laurent FAILLIE wrote:
Yes, I had a look on the .gir, but I only focused on arg definitions :(
In any cases, I don't see any rename-to :

     <function name="timeout_add_seconds"
               c:identifier="g_timeout_add_seconds"
               shadowed-by="timeout_add_seconds_full"
               version="2.14"
               introspectable="0">

So is it the shadowed-by that create the behavior you explained ?

Exactly. Rename-to is used in C sources as an annotation, .gir uses shadowed-by instead. Don't ask me why it is not consistent :-)

Thanks for your code : it is working pretty well :) but is raising also
some (probably) stupid question to me :
How can I mix both Glib and Gtk ? I mean, I can't have both
main_loop:run()
and
Gtk.main()

Gtk.main() internally calls some equivalent of main_loop:run() (and Gtk.main_quit() calls equivalent of main_loop:quit()).

And for new applications, you might consider using Gio.Application (or Gtk.Application), which embeds GMainLoop:run() inside its Gio.Application:run() method. See lgi's samples/gtkpad.lua how to do that.

But more, how can I having a process running and checking if some evens
has to be handled ?
I mean, my main experience with GUI programming is on AmigaOS where you
can use a main loop like here, but you can have also a plain process
working, checking punctually for arriving events or be interrupted by
signals.

Something like :

for(;;){
ImDoingSomeHardWork();
if(waiting_events)
EventsHandler();
     SomeOtherHardWork();
}

How it is possible with GLib and Gtk ?

It is possible, but I have not tried it yet myself; look at g_main_context_iteration() and/or gtk_main_iteration_do() APIs.

But I'd rather avoid that, and structure ImDoingSomeHardWork() and SomeOtherHardWork() to be scheduled by GLib.idle_add(). Note Lua's coroutines can be really helpful here, because you can make ImDoingSomeHardWork() running as coroutine, spiced with coroutine.yield() at 'strategic' places. Then you pass coroutine instance (instead of function) to GLib.idle_add(), and voila, coroutine is periodically resumed when GLib's mainloop has nothing else to do.

hth,
pavel