[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: Luiz Henrique de Figueiredo <lhf@...>
- Date: Fri, 2 Jun 2006 08:24:18 -0300
> 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:
1. write you Lua function as
local function dispatch()
while true do
msg = ...
local response = send(msg)
2. define wait and send to be coroutine.yield
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().
I did someting like that in my token filters, about which I talked at the
Workshop last year, and which I still have to finish and release.