aboutsummaryrefslogtreecommitdiff
path: root/libs/lua/test/trace-globals.lua
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-16 10:58:21 (GMT)
committerPaul Tagliamonte <paultag@fluxbox.org>2012-04-07 02:08:41 (GMT)
commit0fa62fe1598c5b04925c0b7b98d0d00d28d10d88 (patch)
treeccc2dd040a03b294b17abaa4da55ca00ed9b82a7 /libs/lua/test/trace-globals.lua
parent7b6dc2ad72a4c4ecd20eddbfb6f1b4c3bd2a7024 (diff)
downloadfluxbox_paul-0fa62fe1598c5b04925c0b7b98d0d00d28d10d88.zip
fluxbox_paul-0fa62fe1598c5b04925c0b7b98d0d00d28d10d88.tar.bz2
Add lua as an internal library in libs/lua
Diffstat (limited to 'libs/lua/test/trace-globals.lua')
-rw-r--r--libs/lua/test/trace-globals.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/libs/lua/test/trace-globals.lua b/libs/lua/test/trace-globals.lua
new file mode 100644
index 0000000..295e670
--- /dev/null
+++ b/libs/lua/test/trace-globals.lua
@@ -0,0 +1,38 @@
1-- trace assigments to global variables
2
3do
4 -- a tostring that quotes strings. note the use of the original tostring.
5 local _tostring=tostring
6 local tostring=function(a)
7 if type(a)=="string" then
8 return string.format("%q",a)
9 else
10 return _tostring(a)
11 end
12 end
13
14 local log=function (name,old,new)
15 local t=debug.getinfo(3,"Sl")
16 local line=t.currentline
17 io.write(t.short_src)
18 if line>=0 then io.write(":",line) end
19 io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n")
20 end
21
22 local g={}
23 local set=function (t,name,value)
24 log(name,g[name],value)
25 g[name]=value
26 end
27 setmetatable(getfenv(),{__index=g,__newindex=set})
28end
29
30-- an example
31
32a=1
33b=2
34a=10
35b=20
36b=nil
37b=200
38print(a,b,c)