Re: The purpose of LUA_ENVIRONINDEX pseudo index
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: The purpose of LUA_ENVIRONINDEX pseudo index
- From: Jose Luis Hidalgo Valiño <joseluis.hidalgo@...>
- Date: 2006年8月29日 08:57:22 +0200
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)