if local variable in unknown scope gets set 256
, how can know happened?
i'd able 1 value @ time, assuming that's possible.
i have access debug
api.
you can loop on local variables @ current scope inside debug hook , check 1 has value need:
do local seen = {} debug.sethook(function(ev, line) local level = 2 local target = 256 local = 1 while true local name, value = debug.getlocal(level, i) if not name break end if value == target , string.sub(name, 1, 1) ~= '(' , not seen[name] print("at line", line, "variable", name, value) seen[name] = true elseif seen[name] , value ~= target seen[name] = nil end = + 1 end end, "l") end local = 256 local b = 11 = 13 a, b = 256, 256 print("done")
this prints following me:
at line 23 variable 256 @ line 26 variable 256 @ line 26 variable b 256 done
this applies local variables. global variables can iterate on _g
or _env
tables , compare values.
note lines printed lines of next statement , not lines on change happens (as hook stops before line executed).
there 2 other options track variable changes (with limitations): (1) using metamethods , proxy table, , (2) using debugger.