[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Across Lua universes (was Re: lua_pushtable)
- From: Wim Couwenberg <debosberg@...>
- Date: Fri, 4 Jun 2004 12:31:31 -0700 (PDT)
> If the preferred Lua way to handle multiple
> processors and other cases where
> cooperative multi-threading isn't an option is to
> use multiple Lua
For several projects we use such a scheme (multiple
universes) each driven by their own thread, possibly
the main UI thread. We're very happy with this setup.
We did this in Lua 4 and currently I'm doing another
project in Lua 5 based on (roughly) the same ideas.
The basic principle is to allow only a single thread
at a time access to a particular Lua universe. At
least in my experience this works much nicer than
trying to juggle with preempting OS threads on one and
the same state.
> then there needs to be good support for
> packaging stuff up and
> sending it between universes.
Absolutely. But this was already easily achieved in
Lua 4 and Lua 5 added some nice possibilities.
Marshalling only some basic stuff between states (nil,
strings, numbers, (simple) tables) turned out to be
more than sufficient even for pretty nifty
applications. Just because it can be done in Lua 5, I
added marshalling of light userdata, userdata (through
a __copy metamethod), C functions (with upvalues) and
Lua functions (without upvalues.)
> I'm not sure what that
> would look like,
> however. The current thread on Lua persistence might
> be a pointer
Nothing quite that fancy. There is no need to stream
objects, but only to construct them in another
universe. No need for 100% support for all data.
You'll be amazed what can be done with only the
basics. For example, we found no need to marshal tags
/ metatables etc. anywhere in our projects yet...
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.