2017-06-12 21:56:22 +10:00
|
|
|
function skex(s)
|
2017-05-28 04:24:44 +10:00
|
|
|
local c,cs,cT,lT,lP="","",{},{},1
|
2017-06-12 21:56:22 +10:00
|
|
|
local function lf(s)
|
|
|
|
local f=fopen(s,"rb")
|
|
|
|
local nc=fread(f,2048)
|
|
|
|
while nc ~= nil and nc ~= "" do
|
|
|
|
c=c..nc
|
|
|
|
nc=fread(f,2048)
|
2017-05-28 04:24:44 +10:00
|
|
|
end
|
2017-06-12 21:56:22 +10:00
|
|
|
end
|
|
|
|
local function wf(s)
|
|
|
|
local f,c=fopen(s,"wb"),""
|
|
|
|
for k,v in ipairs(lT) do fwrite(f,v.."\n") end
|
|
|
|
fclose(f)
|
|
|
|
end
|
|
|
|
if s then
|
|
|
|
lf(s)
|
2017-05-28 04:24:44 +10:00
|
|
|
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)))
|
2017-06-12 21:56:22 +10:00
|
|
|
elseif cT[1] == "r" then
|
|
|
|
s=cT[2] or s
|
|
|
|
wf(s)
|
2017-05-28 04:24:44 +10:00
|
|
|
elseif cT[1] == "w" then
|
2017-06-12 21:56:22 +10:00
|
|
|
s=cT[2] or s
|
|
|
|
wf(s)
|
2017-05-28 04:24:44 +10:00
|
|
|
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
|
2017-06-12 21:56:22 +10:00
|
|
|
lP=TN(cT[2]) or lP
|
|
|
|
print(lP)
|
|
|
|
elseif cs:sub(1,1) == "!" then
|
|
|
|
c=""
|
|
|
|
for k,v in ipairs(lT) do c=c..v.."\n" end
|
|
|
|
print(pcall(load(cs:sub(2))))
|
2017-05-28 04:24:44 +10:00
|
|
|
else
|
|
|
|
print("?")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|