lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Dec 10, 2001 at 03:36 -0800, Steve Dekorte wrote:
> 
> On Monday, December 10, 2001, at 03:16  PM, Thatcher Ulrich wrote:
> >> Is there a hook that get's called when sleep is
> >> called?
> >
> > Nope.  I don't think it would be hard to add, but I haven't paid much
> > attention to how callbacks work in Lua.  What would you use it for?
> 
> To resume the next object in the list of active objects.

The pattern I had in mind was something like:

void dispatcher()
{
	for each script thread {
		if (thread->status == LUA_SLEEP) {
			thread->status = lua_resume(thread->L);
		} else {
			// restart the thread.
			thread->status = lua_dofile(thread->L,
				 thread->scriptfile);
			// Substitute dobuffer, dostring, etc as desired.
		}
	}
}

Does that look reasonable?  Since sleep() returns back to the host
program anyway, it seems easier to avoid using a callback.

-- 
Thatcher Ulrich <tu@tulrich.com>
http://tulrich.com