From 349d46eb1e7f1d13f5d823e818216b5ef1cee566 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 15 Sep 2016 08:07:32 +0200 Subject: sync with Context as of 2016-09-15 --- lualibs-util-lua.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lualibs-util-lua.lua') 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 -- cgit v1.2.3