From 63050f3bad00098e4ce1ad40413e4f564e787bbf Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Thu, 4 Mar 2021 19:45:34 +0100 Subject: [PATCH] Add text.inputstream --- text.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/text.lua b/text.lua index ea98f61..559c191 100644 --- a/text.lua +++ b/text.lua @@ -50,6 +50,19 @@ end trim_right = trim_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} +} +function inputstream(text) + return setmetatable({text = text, cursor = 0}, inputstream_metatable) +end + + function split(text, delimiter, limit, is_regex) limit = limit or math.huge local no_regex = not is_regex