From 4d5d6c4cb4b523f218941dc43f0aacf5074c4dc8 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 30 Mar 2024 21:28:22 +0000 Subject: pm tells if required --- pm.lua | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/pm.lua b/pm.lua index abeb056..b63c2bc 100644 --- a/pm.lua +++ b/pm.lua @@ -2,6 +2,21 @@ local rbase = "https://g.gh0.pw/ccprogs/plain/" +local function is_required() + local n = 0 + local res = false + while true do + local x = debug.getinfo(n) + if x == nil then break end + n = n + 1 + if x.func == require then + res = true + break + end + end + return res +end + local function perr(err,what) if err then error(what..": "..err) end end @@ -115,9 +130,10 @@ local function dl(pkgname) print"done" end - ---return {manifest=manifest,rd=recursive_depsof,rf=recursive_filesof,dl=dl,cc=clear_cache} - -for i=1,#arg do - dl(arg[i]) +if is_required() then + return {manifest=manifest,rd=recursive_depsof,rf=recursive_filesof,dl=dl,cc=clear_cache} +else + for i=1,#arg do + dl(arg[i]) + end end -- cgit v1.2.3