mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Text inputstream: Allow obtaining cursor position
This commit is contained in:
parent
7eb5f09752
commit
234f6d1ecd
8
text.lua
8
text.lua
@ -62,13 +62,17 @@ function trim_spacing(text)
|
||||
end
|
||||
|
||||
local inputstream_metatable = {
|
||||
__index = {read = function(self, count)
|
||||
__index = {
|
||||
read = function(self, count)
|
||||
local cursor = self.cursor + 1
|
||||
self.cursor = self.cursor + count
|
||||
local text = self.text:sub(cursor, self.cursor)
|
||||
return text ~= "" and text or nil
|
||||
end}
|
||||
end,
|
||||
seek = function(self) return self.cursor end
|
||||
}
|
||||
}
|
||||
--> inputstream "handle"; only allows reading characters (given a count), seeking does not accept any arguments
|
||||
function inputstream(text)
|
||||
return setmetatable({text = text, cursor = 0}, inputstream_metatable)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user