diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-09-19 00:43:31 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-09-19 00:43:31 +0200 |
| commit | 402b97fbdf4857adc5aa80f85fa5e59148e126b7 (patch) | |
| tree | 666e08bf605b3e09064cb965c3596684e3c0da5e /zig-lua/lua-5.4.7/testes/tracegc.lua | |
| parent | 2e2da1fd114edb932954a108ddb6f7359dbb868a (diff) | |
| download | probe-402b97fbdf4857adc5aa80f85fa5e59148e126b7.tar.gz | |
Added debuggers to Nix shell
Diffstat (limited to 'zig-lua/lua-5.4.7/testes/tracegc.lua')
| -rw-r--r-- | zig-lua/lua-5.4.7/testes/tracegc.lua | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/zig-lua/lua-5.4.7/testes/tracegc.lua b/zig-lua/lua-5.4.7/testes/tracegc.lua new file mode 100644 index 0000000..9c5c1b3 --- /dev/null +++ b/zig-lua/lua-5.4.7/testes/tracegc.lua @@ -0,0 +1,40 @@ +-- track collections + +local M = {} + +-- import list +local setmetatable, stderr, collectgarbage = + setmetatable, io.stderr, collectgarbage + +_ENV = nil + +local active = false + + +-- each time a table is collected, remark it for finalization on next +-- cycle +local mt = {} +function mt.__gc (o) + stderr:write'.' -- mark progress + if active then + setmetatable(o, mt) -- remark object for finalization + end +end + + +function M.start () + if not active then + active = true + setmetatable({}, mt) -- create initial object + end +end + + +function M.stop () + if active then + active = false + collectgarbage() -- call finalizer for the last time + end +end + +return M |
