diff options
Diffstat (limited to 'fs.lua')
-rw-r--r-- | fs.lua | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/fs.lua b/fs.lua index 153e611..f612a59 100644 --- a/fs.lua +++ b/fs.lua @@ -4,7 +4,6 @@ -- throwing it, which may be what we want. code depends on this local unistd = require("posix.unistd") local cqueues = require("cqueues") -local dkjson = require("dkjson") local file = {} @@ -33,7 +32,7 @@ end -- buffers are arrays of objects containing "data" (a string) and "index" (their position) -- indexing allows us to avoid recreating string objects -function buffer_length(buf) +local function buffer_length(buf) local total = 0 for _, entry in ipairs(buf) do total = total + #entry.data - entry.index + 1 @@ -42,12 +41,12 @@ function buffer_length(buf) end -- returns nil on empty length -function buffer_get(buf, length) +local function buffer_get(buf, length) local out = {} if not length then length = buffer_length(buf) end while length > 0 do assert(#buf > 0) - + local x = string.sub(buf[1].data, buf[1].index, buf[1].index + length - 1) table.insert(out, x) if #buf[1].data - buf[1].index + 1 <= length then @@ -60,7 +59,7 @@ function buffer_get(buf, length) if out[1] then return table.concat(out) else return nil end end -function buffer_char_index(buf, char) +local function buffer_char_index(buf, char) local num = 1 for _, entry in ipairs(buf) do if string.find(entry.data, char, entry.index, true) then @@ -81,7 +80,7 @@ do assert(buffer_length(test_buf) == 1) end -function try_read(buffer, fd, max) +local function try_read(buffer, fd, max) cqueues.poll({ pollfd = fd, events = function () return "r" end }) local data, _, errno = unistd.read(fd, max) |