Here's one such example: http://williamaadams.wordpress.com/2013/02/23/poor-mans-event-driven-io/ -- William =============================== - Shaping clay is easier than digging it out of the ground. ---------------------------------------- > Date: Fri, 6 Sep 2013 15:20:30 +0200 > From: mike-1309@xxxxxxxxxx > To: luajit@xxxxxxxxxxxxx > Subject: Re: CoCo in 2.0.2 > > Ani A wrote: >> What I want to be able to do, from the Lua functions that I am >> implementing which calls a C function, at that point, if the >> computation takes a while to complete (say, requires network >> access), I should be able to yield(), and once the results are >> available, resume() and continue the Lua script execution. > > You can always yield from Lua code. Which implies the C function > must be non-blocking: it either returns the result immediately or > an indication it cannot do so right now (e.g. EAGAIN in POSIX). > You need a Lua wrapper that yields and retries the operation plus > a coroutine scheduler that resumes the coroutine when e.g. the > file descriptor is readable again. I'm sure there are plenty of > Lua examples for this design pattern out there. > > --Mike >