lua-users home
lua-l archive

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



El 29/08/2006, a las 2:58, Mildred escribió:


For example,
could lua_environindex be used to hold data locally( or private ) to
a C function that can be accessed in successive calls?

I don't know about LUA_ENVIRONINDEX but if you want to keep some
variables between the function call (like static variables in C) you
may find closures useful.

I'm not sure if closures are mutable or not (but it's name suggest they are not mutable), if you want a mutable variable, that can be accessed by a function, you should use one of these pseudo indices:
    - LUA_REGISTRY --> accessible by C code only
- LUA_GLOBALSINDEX ---> the thread environment, for global variables. - LUA_ENVIRONINDEX --> that's new to lua 5.1 and I'm not sure how to use it.

LUA_ENVIRONINDEX seems a way to hold data locally to a set of functions ( or only one ) but without loosing the possibility of access the full global environment (the thread environment) through LUA_GLOBALSINDEX.

In lua 5.1 lua_setfenv "changes" the behavior of LUA_ENVIRONINDEX or LUA_GLOBALSINDEX ? I'm not sure.

Jose L. (PpluX)