lua-users home
lua-l archive

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


On Tue, Jan 11, 2005 at 10:11:16PM -0700, Spencer Schumann wrote:
> > My priority is extremely fast startup and shutdown.
> 
> With this as your priority, you may want to use a single Lua state to
> run all your scripts.  If you use setfenv, you can give each script
> its own global environment to avoid problems with variables leaking
> between scripts.

This brings me to the second thing I was hoping to do. My application in
which I wish to embed Lua is a single-threaded server. However, all of its
I/O operations are non-blocking so as to be able to handle multiple clients.
Using Lua and coroutines I'm hoping to implement concurrent execution of
user scripts.

However, to do this I need to be able to fall out of Lua during any I/O
processing and install event callbacks. And when the I/O request is
finished, restart execution. For instance, if Lua calls something like
lookup()--for a DNS lookup--I need execution to yield and return back to the
C function which started/resumed the execution. What I *don't* want is for
lookup() to recurse back into my application, growing the C stack each time.

Would this be better accomplished using multiple states or does it not
matter? I'm still fuzzy on how I could accomplish this with Lua, or if it's
even possible.

- Bill