Coroutines for C using Lua?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Coroutines for C using Lua?

Patrick Mc(avery-2
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

Reply | Threaded
Open this post in threaded view
|

Re: Coroutines for C using Lua?

Peng Zhicheng
于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.



Reply | Threaded
Open this post in threaded view
|

Re: Coroutines for C using Lua?

Patrick Mc(avery-2

> 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.
>
Hi Peng

Thanks for answering my post, you have cleared things up for me. The GUI
locking problem only exists in my head right now(along with lots of
other problems !) Now that I know the term yieldable C function I can
read about this some more.

Thanks a lot-Patrick