summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-08-03 23:35:19 +0100
committerubq323 <ubq323@ubq323.website>2022-08-03 23:35:19 +0100
commit974bb153bf5fc3665c78e1b24b8373e1233434a8 (patch)
treec007f23164f968718911aaddc622c16ac3d37665
parent07ff4f5e9d3a12f27f1cb20bd7666d2e9dcece08 (diff)
pm
-rw-r--r--pm.lua41
1 files 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()