blob: 5f32a8f9bbe4519aa8ffa75655827de7019746aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-- shows how to trace assigments to global variables
T=newtag() -- tag for tracing
function Ttrace(name) -- trace a global variable
local t={}
settag(t,T)
rawsetglobal(name,t)
end
function Tsetglobal(name,old,new)
write("tracing: ",name," now is ",new,"\n")
old.value=new
end
function Tgetglobal(x,value) -- get the actual value
return value.value
end
settagmethod(T,"getglobal",Tgetglobal)
settagmethod(T,"setglobal",Tsetglobal)
-- now show it working
Ttrace("a")
Ttrace("c")
a=1
b=2
c=3
a=10
b=20
c=30
|