From 7d3e2bd2c4cfd1296d1d6f996d7548de26540d41 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Fri, 15 Feb 2013 16:27:18 -0800 Subject: 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). --- bindings/lua/lunitx/atexit.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 bindings/lua/lunitx/atexit.lua (limited to 'bindings/lua/lunitx/atexit.lua') 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 + -- cgit v1.2.3