mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-26 01:03:46 +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
|
end
|
||||||
|
|
||||||
local inputstream_metatable = {
|
local inputstream_metatable = {
|
||||||
__index = {read = function(self, count)
|
__index = {
|
||||||
|
read = function(self, count)
|
||||||
local cursor = self.cursor + 1
|
local cursor = self.cursor + 1
|
||||||
self.cursor = self.cursor + count
|
self.cursor = self.cursor + count
|
||||||
local text = self.text:sub(cursor, self.cursor)
|
local text = self.text:sub(cursor, self.cursor)
|
||||||
return text ~= "" and text or nil
|
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)
|
function inputstream(text)
|
||||||
return setmetatable({text = text, cursor = 0}, inputstream_metatable)
|
return setmetatable({text = text, cursor = 0}, inputstream_metatable)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user