blob: c3cdddc1051c423640bf3509c97117b269f032ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
local actions = {}
local atexit
if _VERSION >= 'Lua 5.2' then
atexit = function (fn)
actions[#actions+1] = setmetatable({}, { __gc = fn })
end
else
local newproxy = newproxy
local debug = debug
local assert = assert
local setmetatable = setmetatable
local function gc(fn)
local p = assert(newproxy())
assert(debug.setmetatable(p, { __gc = fn }))
return p
end
atexit = function (fn)
actions[#actions+1] = gc(fn)
end
end
return atexit
|