lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote:
Lua functions do not use the thread environment. Instead, Lua
functions use the function environment for all global accesses. Lua C
functions, by convention, (for better or worse) use the thread
environment (LUA_GLOBALSINDEX) instead of an environment index
(LUA_ENVIRONINDEX). Your Lua function inherits the environment of the
thread it was created in. In your example, that is the main thread
environment (a = 0).

Lua 5.2 will simplify this (for better or worse). The thread environment
will be removed, as well as the LUA_GLOBALSINDEX pseudo-index.
C functions will behave more similar to Lua functions, with easy access
only to their own environment. The main global table is still accessible,
as _G in Lua and via the registry in C.

-- Roberto

Hi Roberto,

Does that mean in 5.2, I can't have any per-thread data? It has to be global to a Lua state or private to a function?

Christian Tellefsen
Funcom