From 974bb153bf5fc3665c78e1b24b8373e1233434a8 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 3 Aug 2022 23:35:19 +0100 Subject: pm --- pm.lua | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/pm.lua b/pm.lua index d1323b1..6983138 100644 --- a/pm.lua +++ b/pm.lua @@ -1,8 +1,45 @@ +-- 'package manager' + +local rbase = "https://g.gh0.pw/ccprogs/plain/" + +local function perr(err,what) + if err then error(what..": "..err) end +end + +local function manifest(pkgname) + print("fetching manifest of '"..pkgname.."'...") + local ,err = http.get(rbase..pkgname..".dat") + perr(err,"http.get") + local files={} + local files_present=false + local deps={} + for line in res:gmatch"[^\n]+" do + local op,argstart = line:match "^(%w+)%s+()" + if op then + argstr = line:sub(argstart) + local args = {} + for arg in argstr:gmatch"[^ ]+" do + table.insert(args,arg) + end + + if op == "dep" then + for _,arg in ipairs(args) do deps[arg]=true end + elseif op == "file" then + files_present = true + for _,arg in ipairs(args) do files[arg]=true end + end + end + end + if not files_present then files[pkgname]=true end + return {files=files,deps=deps} +end + + local function dl(filename) local file,err=fs.open("/"..filename..".lua","w") - if err then error("fs.open",err) end + if err then error("fs.open "..err) end local res,err = http.get("https://g.gh0.pw/ccprogs/plain/"..filename..".lua") - if err then error("http.get",err) end + if err then error("http.get "..err) end file.write(res.readAll()) file.flush() file.close() -- cgit v1.2.3