OC-PsychOS/exec/lmk.lua

74 lines
1.4 KiB
Lua

local tA = {...}
local modlistf = tA[1]
local nk = ""
local oprint = print
print(modlistf)
function print(...)
if tA[2] then
oprint(...)
end
end
f = io.open(modlistf,"rb")
if not f then error("no input file") end
local ofile = nil
local c=f:read("*a")
f:close()
local n=1
local function wcfile()
if ofile then
f=io.open(ofile,"wb")
if f then
oprint("writing file "..ofile)
f:write(nk)
f:close()
else
oprint("warning: unable to open file "..ofile.." to write")
end
end
end
local function apfile(fp)
local f=io.open(fp,"rb")
if f then
nk=nk..f:read("*a")
f:close()
end
end
for line in c:gmatch("[^\r\n]+") do
print(line)
local tw = {}
for w in line:gmatch("%S+") do
tw[#tw+1] = w
end
n=n+1
if tw[1] == "ofile" then
wcfile()
ofile = tw[2]
nk=""
elseif tw[1] == "exec" then
os.execute(tw[2])
elseif tw[1] == "lexec" then
local f=io.open(tw[2],"rb")
if f then
local fc = f:read("*a")
print(fc)
print(pcall(load(fc)))
end
f:close()
elseif tw[1] == "fwrap" then
nk=nk.."function "..tw[2].."(...)\n"
apfile(tw[3])
nk=nk.."\nend\n"
elseif tw[1] == "libwrap" then
nk=nk.."function "..tw[2].."(...)\n"
apfile(tw[3])
nk=nk.."\nend\n_G."..tw[2].." = "..tw[2].."()\n"
elseif tw[1] == "alias" then
nk=nk..tw[2].."="..tw[3].."\n"
elseif tw[1] == "include" then
apfile(tw[2])
elseif #tw == 1 then
apfile(line)
end
end
wcfile()