[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Can I stop and continue lua code from a C function called from lua?
- From: Sam Roberts <sroberts@...>
- Date: Fri, 2 Jun 2006 09:19:48 -0700
On Fri, Jun 02, 2006 at 08:24:18AM -0300, Luiz Henrique de Figueiredo wrote:
> > I want it to look from
> > lua like its doing a blocking wait for a response message (or error) to
> > come back, but I need to return control to the main C message loop.
> > Any suggestions on how to do this? Some cool pure lua coroutine magic?
> Sure, coroutines are the perfect tool for that:
Great, thanks, that lua_resume() and lua_yield() look exactly like what
I want, I will try this.
> 3. create a new Lua thread and call DISPATCH from you C program in this thread.
> The first time DISPATCH is called, it just returns. You do nothing.
> In you C main loop, just keep calling DISPATCH, now with the response.
> Depending on what you want to do, you may be able to avoid wait().
One question, its not clear (from sec 3.20 of the 5.0 ref man) whether I
MUST call lua_newthread() to get a lua_State that can be passed as an
argument to lua_resume().
If I only want one coroutine, can I call lua_resume() on the "main"
state that I created with lua_open()?