interplane.Get Omega
Read in your language

lua

[Ported from github.com/lua/lua] Cast in 'rl_readline_name'

Brought by drakestapleton

branch master Branches Tags History

lua / testes / tracegc.lua

45 lines · 855 bytes Raw Blame History
1-- track collections
2
3
4local M = {}
5
6-- import list
7local stderr, collectgarbage = io.stderr, collectgarbage
8
9-- the debug version of setmetatable does not create any object (such as
10-- a '__metatable' string), and so it is more appropriate to be used in
11-- a finalizer
12local setmetatable = require"debug".setmetatable
13
14global none
15
16local active = false
17
18
19-- each time a table is collected, remark it for finalization on next
20-- cycle
21local mt = {}
22function mt.__gc (o)
23 stderr:write'.' -- mark progress
24 if active then
25 setmetatable(o, mt) -- remark object for finalization
26 end
27end
28
29
30function M.start ()
31 if not active then
32 active = true
33 setmetatable({}, mt) -- create initial object
34 end
35end
36
37
38function M.stop ()
39 if active then
40 active = false
41 collectgarbage() -- call finalizer for the last time
42 end
43end
44
45return M