[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LUA missing lua_pushuserdata()?
- From: Sean Conner <sean@...>
- Date: Wed, 7 Oct 2009 04:01:55 -0400
It was thus said that the Great Wesley Smith once stated:
> Use coroutines for this. It's a much better model for handling event
> driven scripting situations where you need to maintain state and
> calculations between events.
That's what I'm trying to use. Sorry if I didn't make that clear.
The logic so far (which I haven't tested yet) is:
C code Lua code
accept()
lua_resume()
blah
blah
blah socket:read() (which calls
coroutine.yield())
epoll_add(socket)
ev = epoll_wait()
if (ev.read) collect data
if (enough data)
lua_resume()
blah
blah
socket:write() (coroutine.yield())
ev = epoll_wait()
if (can-write-data)
{
write data
if no more data
lua_resume()
}
...
thread.exit() (coroutine.yield())
epoll_remove(socket)
close(socket)
free(luathread)
-spc (Hope that makes some sense ... )