From 2df1d2f52d2c1de503978b687b116372e672eb6d Mon Sep 17 00:00:00 2001 From: Peter Nerlich Date: Mon, 7 Dec 2020 14:25:09 +0100 Subject: [PATCH] simplify split function for our usecase --- lcd.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lcd.lua b/lcd.lua index 478fce0..27eb4d8 100644 --- a/lcd.lua +++ b/lcd.lua @@ -32,13 +32,16 @@ local CHAR_WIDTH = 5 local split = function(s, pat) -- adapted from https://stackoverflow.com/a/1647577/4067384 - pat = pat or '%s+' - local st, g = 1, string.gmatch(s, "()("..pat..")") - local function getter(segs, seps, sep, cap1, ...) - st = sep and seps + #sep - return string.sub(s, segs, (seps or 0) - 1), cap1 or sep, ... + -- simplified for our only usecase + local st, g = 1, s:gmatch("()("..pat..")") + local function getter() + if st then + local segs, seps, sep = st, g() + st = sep and seps + #sep + return s:sub(segs, (seps or 0) - 1) + end end - return function() if st then return getter(st, g()) end end + return getter end local create_lines = function(text)