lua-users home
lua-l archive

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


On Mon, Jul 14, 2008 at 10:49 PM, Tim Maxwell <timmaxw@gmail.com> wrote:
> Hi,
>
> The environment system is a powerful new feature for Lua. It seems to me
> that the globals table accessible through LUA_GLOBALSINDEX is just a special
> case of the environment table - unless I am mistaken, LUA_GLOBALSINDEX
> simply refers to the environment table that was created for the first Lua
> state. If I'm wrong, disregard the rest of this message.
>
> Perhaps LUA_GLOBALSINDEX is unnecessary. lua_getglobal and lua_setglobal
> could be redirected to access LUA_ENVIRONINDEX instead of LUA_GLOBALSINDEX.
> Most global variable access should go to the environment table anyway, so
> lua_getglobal and lua_setglobal would be more useful if they want to the
> environment table. Other functions that use LUA_GLOBALSINDEX should probably
> go to LUA_ENVIRONINDEX as well.
>
> Can anybody think of a use for LUA_GLOBALSINDEX over LUA_ENVIRONINDEX?
>
> Is there anything that this change would break?
>
> Is LUA_GLOBALSINDEX already being retired?
>
> Tim Maxwell
>

LUA_GLOBALSINDEX is the environment of the running thread.
LUA_ENVIRONINDEX is useful for sharing an environment across many
userdata/functions in C (especially useful since C functions cannot
share upvalues). Usually, you will want to use LUA_GLOBALSINDEX.

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant