lua-users home
lua-l archive

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


于2012年3月26日 8:55:16,Patrick写到:
Hi List

I have a C application half written. It uses gtk and gstreamer. It plays a video and then pauses the video and prompts a child to try to pronounce a word.

Now I am thinking about redoing the logic of when the video is paused. I am thinking about writing one long lived Lua function, wrapping the C/Gstreamer/GTK as a Lua library and then calling it from Lua. I am thinking that if I use coroutines I can avoid locking up the GUI with a long lived function call.

Does this sound logical?


Thanks for reading-Patrick


sorry, but I don't quite get your problem:
By "locking up the GUI", do you mean the prompt window (or maybe a modal dialog) locks its parent/owener window? If so, I don't think there is problem, since in all window system a modal dialog is supposed to take all the event processing work for the parent window.

here are some tips I hope are helpful.
the GUI is locked up because some event/message callback does not return quickly to the event loop, so no new events can be dispatched.

you should divide the long event callback into shorter parts: you may use coroutines to achieve this, or you may turn the big event into many smaller events.

and you should be aware that the `plain' Lua 5.1 does not allow coroutine to yield across a C function boundary, but the luajit (or the coco patch with it, see the website of luajit) does.

while Lua 5.2 support yieldable C function, you have to manually deal with the continous part.