summaryrefslogtreecommitdiff
path: root/bindings/lua/lunitx/atexit.lua
diff options
context:
space:
mode:
authorJosh Haberman <haberman@google.com>2013-02-15 16:27:18 -0800
committerJosh Haberman <haberman@google.com>2013-02-15 16:27:18 -0800
commit7d3e2bd2c4cfd1296d1d6f996d7548de26540d41 (patch)
treeb4b35967b3322c65cfb1a32220e8718de09d85fc /bindings/lua/lunitx/atexit.lua
parentea198bdcf947ba4bd51474bdd4f7b82b5e4cf41d (diff)
Sync with 8 months of Google-internal development.
Many things have changed and been simplified. The memory-management story for upb_def and upb_handlers is much more robust; upb_def and upb_handlers should be fairly stable interfaces now. There is still much work to do for the runtime component (upb_sink).
Diffstat (limited to 'bindings/lua/lunitx/atexit.lua')
-rw-r--r--bindings/lua/lunitx/atexit.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/bindings/lua/lunitx/atexit.lua b/bindings/lua/lunitx/atexit.lua
new file mode 100644
index 0000000..c3cdddc
--- /dev/null
+++ b/bindings/lua/lunitx/atexit.lua
@@ -0,0 +1,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
+
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback