64 lines
1.3 KiB
Lua
64 lines
1.3 KiB
Lua
function skex(s,f)
|
|
local c,cs,cT,lT,lP="","",{},{},1
|
|
if s then
|
|
if f then
|
|
c=s
|
|
else
|
|
local f=fopen(s,"rb")
|
|
local nc=fread(f,2048)
|
|
while nc ~= nil and nc ~= "" do
|
|
c=c..nc
|
|
nc=fread(f,2048)
|
|
end
|
|
end
|
|
for l in c:gmatch("(.-)\n") do lT[#lT+1]=l end
|
|
end
|
|
while true do
|
|
cs=readln()
|
|
cT={}
|
|
for w in cs:gmatch("%S+") do cT[#cT+1]=w end
|
|
if cT[1] == "q" then break
|
|
elseif cT[1] == "l" then
|
|
for i = (TN(cT[2]) or 1), (TN(cT[3]) or #lT) do
|
|
print(TS(i).."\t"..(lT[i] or ""))
|
|
end
|
|
elseif cT[1] == "a" or cT[1] == "i" or cT[1] == "s" then
|
|
if TN(cT[2]) then lP=TN(cT[2]) end
|
|
if cT[1] == "s" then for i = 1,TN(cT[3]) do T.remove(lT,i+(TN(cT[2])-1)) end end
|
|
if cT[1] == "a" then lP=lP+1 end
|
|
while true do
|
|
cs=readln()
|
|
if cs~="." then
|
|
T.insert(lT,lP,cs)
|
|
lP=lP+1
|
|
else break end
|
|
end
|
|
elseif cT[1] == "f" then
|
|
s=cT[2] or s
|
|
print(s)
|
|
elseif cT[1] == "e" then
|
|
c=""
|
|
for k,v in ipairs(lT) do c=c..v.."\n" end
|
|
print(pcall(load(c)))
|
|
elseif cT[1] == "w" then
|
|
f=fopen(s,"wb")
|
|
c=""
|
|
for k,v in ipairs(lT) do fwrite(f,v.."\n") end
|
|
fclose(f)
|
|
elseif cT[1] == "d" then
|
|
for i = 1, TN(cT[3])-TN(cT[2]) do
|
|
T.remove(lT,cT[2])
|
|
end
|
|
elseif cT[1] == "p" then
|
|
nPT=TN(cT[2])
|
|
if nPT then
|
|
lP=nPT
|
|
else
|
|
print(lP)
|
|
end
|
|
else
|
|
print("?")
|
|
end
|
|
end
|
|
end
|