lua-users home
lua-l archive

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


On Wednesday, December 19, 2007 Leo Razoumov wrote: 

> Let say, we have C-closure foo. I will change its environmental table
> with lua_setfenv. As a result, LUA_ENVIRONINDEX pseudo-index will
> reference the new environment table, while LUA_GLOBALSINDEX is not
> changed and refers to the "thread environment".
> lua_getglobal/lua_setglobal functions use environment table at
> LUA_GLOBALSINDEX location and will not see foo's new function
> environment.

> Am I missing something??

Assuming there is a table stored in the C closure's environment, to
store a value in the table:

    lua_pushliteral (L, "somevalue");               /* value to store */
    lua_setfield (L, LUA_ENVIRONINDEX, "somekey");  /* key */

and to retrieve it

    lua_getfield (L, LUA_ENVIRONINDEX, "somekey");

e

-- 
Doug Currie
Londonderry, NH, USA