From dd629473b828f44a6139f6779e225c1e1f39cdca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 11 Oct 2021 21:24:21 +0800 Subject: stash --- make/bootstrap.lua | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'make/bootstrap.lua') diff --git a/make/bootstrap.lua b/make/bootstrap.lua index 34e8a363..cf908b67 100644 --- a/make/bootstrap.lua +++ b/make/bootstrap.lua @@ -1,7 +1,4 @@ -local args = {} -local sep = package.config:sub(1,1) -local main = '.' .. sep .. 'main.lua' - +local main local i = 1 while arg[i] do if arg[i] == '-E' then @@ -9,20 +6,42 @@ while arg[i] do i = i + 1 local expr = assert(arg[i], "'-e' needs argument") assert(load(expr, "=(command line)"))() - elseif arg[i]:sub(1, 1) == '-' then - args[#args+1] = arg[i] - else - main = arg[i] + -- TODO + return + elseif not main and arg[i]:sub(1, 1) ~= '-' then + main = i + end +end + +if main then + for i = -1, -999, -1 do + if not arg[i] then + for j = i + 1, -1 do + arg[j - main + 1] = arg[j] + end + break + end end - i = i + 1 + for j = 1, #arg do + arg[j - main] = arg[j] + end + for j = #arg - main + 1, #arg do + arg[j] = nil + end +else + arg[0] = 'main.lua' +end + +for k, v in pairs(arg) do + print(k, v) end local root; do - local sepp = sep - if sepp == '\\' then - sepp = '/\\' + local sep = package.config:sub(1,1) + if sep == '\\' then + sep = '/\\' end - local pattern = "["..sepp.."][^"..sepp.."]+" + local pattern = "["..sep.."][^"..sep.."]+" root = package.cpath:match("([^;]+)"..pattern..pattern..pattern.."$") end @@ -34,4 +53,4 @@ package.path = table.concat({ root .. "/script/?/init.lua", }, ";") -assert(loadfile(main))(table.unpack(args)) +assert(loadfile(arg[0]))(table.unpack(arg)) -- cgit v1.2.3