lua-users home
lua-l archive

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

Am 18.04.2013 02:43 schröbte Steve Litt:
On Wed, 17 Apr 2013 22:42:38 +0200
Dirk Laurie <> wrote:

2013/4/17 Steve Litt <>:

Is there any way to protect every last bit of _ENV? If so, I could
run the program and see every place where a global is being set.

Sure, see Programming in Lua by Roberto Ierusalimschy,

    13.4.4 – Tracking Table Accesses.

Thanks Dirk,

That didn't work out quite as well as I'd hoped. It works just fine
with a global table named t, but when I change it to _G, it doesn't
work. Here's the program:



-- keep a private access to original table
local _forbidden = _G

-- create proxy
_G = {}

That won't work, since _G is just an additional reference to (the value returned by) getfenv() or _ENV (depending on the Lua version). Changing it will only affect code that explicitly uses _G. For the rest you will have to replace the current environment using setfenv or assignment to _ENV.