bliss

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

commit 2436e78f7ace9dd9f1124a57376b87261b12f307
parent 4228cf8fd39e1430cb5b5f89996b62b1f9d3e554
Author: phoebos <ben@bvnf.space>
Date:   Sun, 16 Jul 2023 18:47:27 +0100

move atexit into env

Diffstat:
Mbliss/utils.lua | 12++++++------
Mcontrib/bliss-fulldepends | 2+-
Mdoc.txt | 4++--
Mmain.lua | 2+-
Mtest.lua | 2+-
5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/bliss/utils.lua b/bliss/utils.lua @@ -66,8 +66,8 @@ function setup() local o = os.exit os.exit = function(code, close) o(code, not close) end - local atexit = trap_on(env) - return env, atexit + trap_on(env) + return env end function setup_colors() @@ -110,13 +110,13 @@ 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?) - local atexit = setmetatable({}, {__gc = get_pkg_clean(env)}) - return atexit + env.atexit = setmetatable({}, {__gc = get_pkg_clean(env)}) + return env.atexit end -function trap_off(atexit) +function trap_off(env) signal.signal(signal.SIGINT, signal.SIG_DFL) - setmetatable(atexit, {}) + setmetatable(env.atexit, {}) end function split(s, sep) diff --git a/contrib/bliss-fulldepends b/contrib/bliss-fulldepends @@ -25,7 +25,7 @@ if arg[1] == "-h" then os.exit() end -local env, atexit = bliss.setup() +local env = bliss.setup() table.insert(env.PATH, 1, env.sys_db) lists(env, arg) diff --git a/doc.txt b/doc.txt @@ -18,9 +18,9 @@ OVERVIEW Setup the environment (colors, read KISS_* variables): - local env, atexit = bliss.setup() + local env = bliss.setup() -atexit must be kept in scope until the end of the program because it implements +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. diff --git a/main.lua b/main.lua @@ -58,5 +58,5 @@ local function args(env, arg) end end -local env, atexit = bliss.setup() +local env = bliss.setup() args(env, arg) diff --git a/test.lua b/test.lua @@ -2,7 +2,7 @@ bliss = require "bliss" function tts(t) local s = "{ " local sep = "" for k,v in pairs(t) do s = s..sep..k.."="..v sep = ", " end return s .. " }" end -env, atexit = bliss.setup() +env = bliss.setup() for k,v in pairs(env) do if "table" == type(v) then print(k, tts(v))