aboutsummaryrefslogtreecommitdiff
path: root/testes/tracegc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/tracegc.lua')
-rw-r--r--testes/tracegc.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/testes/tracegc.lua b/testes/tracegc.lua
new file mode 100644
index 00000000..9c5c1b3f
--- /dev/null
+++ b/testes/tracegc.lua
@@ -0,0 +1,40 @@
1-- track collections
2
3local M = {}
4
5-- import list
6local setmetatable, stderr, collectgarbage =
7 setmetatable, io.stderr, collectgarbage
8
9_ENV = nil
10
11local active = false
12
13
14-- each time a table is collected, remark it for finalization on next
15-- cycle
16local mt = {}
17function mt.__gc (o)
18 stderr:write'.' -- mark progress
19 if active then
20 setmetatable(o, mt) -- remark object for finalization
21 end
22end
23
24
25function M.start ()
26 if not active then
27 active = true
28 setmetatable({}, mt) -- create initial object
29 end
30end
31
32
33function M.stop ()
34 if active then
35 active = false
36 collectgarbage() -- call finalizer for the last time
37 end
38end
39
40return M