mirror of
https://github.com/minetest-mods/digilines.git
synced 2024-09-25 13:20:25 +02:00
simplify split function for our usecase
This commit is contained in:
parent
6651949665
commit
2df1d2f52d
13
lcd.lua
13
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, ...)
|
||||
-- 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 string.sub(s, segs, (seps or 0) - 1), cap1 or sep, ...
|
||||
return s:sub(segs, (seps or 0) - 1)
|
||||
end
|
||||
return function() if st then return getter(st, g()) end end
|
||||
end
|
||||
return getter
|
||||
end
|
||||
|
||||
local create_lines = function(text)
|
||||
|
|
Loading…
Reference in New Issue
Block a user