bliss

KISS in Lua
git clone git://bvnf.space/bliss.git
Log | Files | Refs | README | LICENSE

commit e1a5729d78943519c096e755e215592027877606
parent 580ce7e291f0833c0ca32e791a66505690791898
Author: phoebos <ben@bvnf.space>
Date:   Mon, 11 Nov 2024 21:28:06 +0000

remove __gc finalizer and make env.atexit() the cleanup function

This improves compatibility with other version of Lua

Diffstat:
Mbliss/utils.lua | 10++++++----
Mcontrib/bliss-fulldepends | 1+
Mcontrib/bliss-makedepends | 2++
Mdoc.txt | 6+++---
Mmain.lua | 3+--
5 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/bliss/utils.lua b/bliss/utils.lua @@ -70,12 +70,14 @@ function setup() mkdirp(env.ROOT .. "/") mkdirp(env.src_dir, env.log_dir, env.bin_dir, env.mak_dir, env.pkg_dir, env.tar_dir, env.tmp_dir) + --trap_on(env) + local atexit = get_pkg_clean(env) + env.atexit = atexit -- make sure os.exit always closes the Lua state local o = os.exit - os.exit = function(code, close) o(code, not close) end + os.exit = function(code, close) atexit(); o(code, true) end - trap_on(env) return env end @@ -126,7 +128,7 @@ function trap_on(env) signal.signal(signal.SIGINT, function () os.exit(false) end) -- use a finalizer to get pkg_clean to run on EXIT. A reference to atexit must -- be kept for the whole duration of the program (should it be a global?) - env.atexit = setmetatable({}, {__gc = get_pkg_clean(env)}) + --env.atexit = setmetatable({}, {__gc = get_pkg_clean(env)}) return env.atexit end @@ -134,7 +136,7 @@ end -- @tparam env env function trap_off(env) signal.signal(signal.SIGINT, signal.SIG_IGN) - setmetatable(env.atexit, {}) + --setmetatable(env.atexit, {}) end --- Split a string. diff --git a/contrib/bliss-fulldepends b/contrib/bliss-fulldepends @@ -29,3 +29,4 @@ local env = bliss.setup() table.insert(env.PATH, 1, env.sys_db) lists(env, arg) +env.atexit() diff --git a/contrib/bliss-makedepends b/contrib/bliss-makedepends @@ -28,3 +28,5 @@ end table.sort(makedeps) for _,v in ipairs(makedeps) do print(v) end + +env.atexit() diff --git a/doc.txt b/doc.txt @@ -20,9 +20,9 @@ Setup the environment (colors, read KISS_* variables): local env = bliss.setup() -env must be kept in scope until the end of the program because env.atexit implements -an EXIT handler by means of a finalizer (__gc). Beware that os.exit has been -monkey-patched so that the Lua state is properly closed by default. +Before the end of a program you must call env.atexit() which cleans up temporary +directories etc. Beware that os.exit has been monkey-patched so that the Lua +state is properly closed by default. BLAKE3 wrapper -------------- diff --git a/main.lua b/main.lua @@ -89,8 +89,6 @@ local function args(env, arg) print(debug.traceback()) end, env, arg) then - bliss.log("An exception was caught, not removing temporary files") - bliss.trap_off(env) os.exit(1) end else @@ -101,3 +99,4 @@ end local env = bliss.setup() args(env, arg) +env.atexit()