Files and Streams
Cursor Read
A cursor models stream position without touching the filesystem.
Cursor Read
cursor_read.lua
local width =
local source = "abcdef"
local cursor = 1
local chunk = string.sub(source, cursor, cursor + width - 1)
cursor = cursor + width
print("width=" .. width)
print("chunk=" .. chunk)
print("cursor=" .. cursor)
local width =
local source = "abcdef"
local cursor = 1
local chunk = string.sub(source, cursor, cursor + width - 1)
cursor = cursor + width
print("width=" .. width)
print("chunk=" .. chunk)
print("cursor=" .. cursor)
local width =
local source = "abcdef"
local cursor = 1
local chunk = string.sub(source, cursor, cursor + width - 1)
cursor = cursor + width
print("width=" .. width)
print("chunk=" .. chunk)
print("cursor=" .. cursor)
cursor
After reading a chunk, move the cursor to the next unread position.