This prints 5 and then 6. It's supposed to add 1 to any variable set, so a
should be 6 and b
should be 6, but __newindex
doesn't affect a
because it was declared locally. Is there any way to filter local variables?
01 | do |
02 | local e = { print = print } |
03 | setfenv ( 1 , setmetatable ( { } , { |
04 | __index = function (t,k) |
05 | return e [ k ] or loadstring ( 'return ' ..k)() |
06 | end , |
07 | __newindex = function (t,k,v) |
08 | e [ k ] = v+ 1 |
09 | end |
10 | } )) |
11 | end |
12 |
13 | local a = 5 |
14 | print (a) |
15 |
16 | b = 5 |
17 | print (b) |
Local variables can't be found unless you're using the debug library; here But it's useless in ROBLOX.