summaryrefslogtreecommitdiff
path: root/lualibs-util-lua.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lualibs-util-lua.lua')
-rw-r--r--lualibs-util-lua.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/lualibs-util-lua.lua b/lualibs-util-lua.lua
index e1dcdc9..b334600 100644
--- a/lualibs-util-lua.lua
+++ b/lualibs-util-lua.lua
@@ -158,3 +158,21 @@ end
-- luautilities.registerdatatype(lpeg.P("!"),"lpeg")
--
-- print(luautilities.datatype(lpeg.P("oeps")))
+
+-- These finalizers will only be invoked when we have a proper lua_close
+-- call (which is not happening in luatex tex node yes) or finish with an
+-- os.exit(n,true).
+
+local finalizers = { }
+
+setmetatable(finalizers, {
+ __gc = function(t)
+ for i=1,#t do
+ pcall(t[i]) -- let's not crash
+ end
+ end
+} )
+
+function luautilities.registerfinalizer(f)
+ finalizers[#finalizers+1] = f
+end