[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: The purpose of LUA_ENVIRONINDEX pseudo index
- From: Luis Carvalho <carvalho@...>
- Date: Tue, 29 Aug 2006 17:47:07 -0400
> Wow!!!, thank you for the explanation now I have a new understanding
> about lua stack and its environments. Definitely the purpose of
> pseudo-indices is not very clear in the manual. I thought that
> objects at pseudo-indices were special objects that can be accessed
> but can not be changed because they are not really in the current
> stack. I was completely wrong.
You misinterpreted it. The manual is actually clear, although terse:
"Pseudo-indices are used to access the thread environment, the function
environment, the registry, and the upvalues of a C function."
That's their purpose. :) Moreover,
"Unless otherwise noted, any function that accepts valid indices can also be
called with pseudo-indices(...)"
and so lua_replace is valid for pseudo-indices, while lua_remove is not.
> That means , for example, a function can change the global thread
> environment or even the registry with lua_replace(L,
> LUA_GLOBALSINDEX, ) or lua_replace(L, LUA_REGISTRYINDEX, ) , isn't
> it? Now I think about it, it seems quite reasonable.
Yes, that's right.
A mathematician is a device for turning coffee into theorems.
-- P. Erdos
Applied Math PhD Student - Brown University
PGP Key: E820854A <firstname.lastname@example.org>