lua-users home
lua-l archive

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

> Is there any reason that I shouldn't just launch a new embedded lua
> interpreter for each "team" that uses a lua-based AI, to avoid
> all the possible scoping issues and such?  The total number of
> concurrent lua interpreters is likely to be a handful at most, which 
> doesn't seem like it would require too much memory, etc.  It looks
> more attractive than the alternative of enforcing scope on multiple
> chunks handled by the same interpreter. 

Some reasons for not using mutiple Lua states are the added memory,
complexity, and CPU costs.

Each state has its own memory pool and performs its GC separately from
other states.

Enforcing scope is not really as much of a pain as it might seem.

You can rather easily set up multiple lua environments, each with its
own set of globals, all coexisting in the same Lua state.

Have a look at loadfile() and the environment handling functions
getfenv() and setfenv().

Also do a search for "sandbox" in the archives.