changed some stuff in buffer.lua, work in progress.

This commit is contained in:
Izaya 2017-08-03 00:27:16 +10:00
parent 26f017fd56
commit fcf9599abe

View File

@ -30,4 +30,73 @@ function buffer.create(w,c) -- worker, close
w(t)
return t
end
function buffer.ucreate()
local b = {}
b.b,b.s = "","open"
function b.write(s,d)
if b.s == "open" then
s.b = s.b .. tostring(d)
return(tostring(d):len())
else return false end
end
function b.read(s,l)
if b.s == "open" then
if type(l) == "number" then
local ns,bs=s.b:sub(1,l+1),s.b:sub(l+2)
s.b = bs
return ns
elseif type(l) == "string" then
if l == "*a" then
local oS = s.b
s.b = ""
return oS
elseif l == "*l" then
local S=s.b:find("\n") or #s.b
local rs = sb:sub(1,S-1)
s.b=s.b:sub(S+1)
return rs
else return false end
else return false end
else return false end
end
function b.close(s)
s="closed"
end
return b
end
function buffer.bcreate()
local b1, b2 = {}, {}
b1.c, b2.c, b1.b, b2.b = 1, 2, "", ""
local function wt(s,d)
if s.c == 1 then s = b2 else s = b1 end -- I'm a terrible person
if b.s == "open" then
s.b = s.b .. tostring(d)
return(tostring(d):len())
else return false end
end
local function rd(s,d)
if s.c == 1 then s = b2 else s = b1 end
if b.s == "open" then
if type(l) == "number" then
local ns,bs=s.b:sub(1,l+1),s.b:sub(l+2)
s.b = bs
return ns
elseif type(l) == "string" then
if l == "*a" then
local oS = s.b
s.b = ""
return oS
elseif l == "*l" then
local S=s.b:find("\n") or #s.b
local rs = sb:sub(1,S-1)
s.b=s.b:sub(S+1)
return rs
else return false end
else return false end
else return false end
end
local function cl(s)
b1.s = "closed"
b2.s = "closed"
end
end