mirror of
https://github.com/appgurueu/modlib.git
synced 2024-12-22 21:32:27 +01:00
Text inputstream: Allow obtaining cursor position
This commit is contained in:
parent
7eb5f09752
commit
234f6d1ecd
16
text.lua
16
text.lua
@ -62,13 +62,17 @@ function trim_spacing(text)
|
||||
end
|
||||
|
||||
local inputstream_metatable = {
|
||||
__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}
|
||||
__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,
|
||||
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