lua-users home
lua-l archive

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

About the on-going discussion on multiple threads:

Like Roberto said, multiple threads of execution in Lua would require
support on the C part, something that neither ANSI C nor POSIX can give.

Now, it seems to me that when people talk about multiple threads they mean
multiple interpreters, as in Tcl.
Lua does not support multiple interpreters, but it does provide ways to
implement multiple environments.
By multiple environments I mean multiple global environments, so that a
variable can have the same name in two environments, but different values,
or exist only in one environment, etc.

Multiple environments are easy to implement in Lua.
One way is as Roberto mentioned: use tables to save and restore the global
Another way is to use the setglobal/getglobal tag methods.
In this solution, these tag methods are used to filter and redirect requests
to read and write the global environment, say to tables.
To switch environments, simply change the handlers for setglobal/getglobal.

Maybe this should be in the FAQ (which is in desperate need of updating).