summaryrefslogtreecommitdiff
path: root/test/trace.lua
diff options
context:
space:
mode:
authorLua Team <team@lua.org>1998-07-11 12:00:00 +0000
committerrepogen <>1998-07-11 12:00:00 +0000
commit377347776f1f3d820f92151f70bec667f96d5e6b (patch)
treecdb3ba26158df33547dfe765547177afcee119d1 /test/trace.lua
parent4f8c5d0f284e1f4da717aea5008915f185cd2e05 (diff)
downloadlua-github-3.1.tar.gz
Lua 3.13.1
Diffstat (limited to 'test/trace.lua')
-rw-r--r--test/trace.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/trace.lua b/test/trace.lua
new file mode 100644
index 00000000..5f32a8f9
--- /dev/null
+++ b/test/trace.lua
@@ -0,0 +1,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