diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/supportlib.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/supportlib.lua b/lib/supportlib.lua index 8565b8e..d734a1e 100644 --- a/lib/supportlib.lua +++ b/lib/supportlib.lua @@ -102,3 +102,27 @@ function hexdump(inp, from, to, width) print(outstring) end + + +-- +-- Splits a string given a separator character into an array. +-- + +function split(str, at) + local splut = {} + + if (type(str) ~= "string") then return nil end + if (not str) then str = "" end + + if (not at) then + table.insert(splut, str) + else + for n, c in string.gfind(str, '([^%'..at..']*)(%'..at..'?)') do + table.insert(splut, n) + + if (c == '') then break end + end + end + + return splut +end |