summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2007-05-28 06:52:21 +0000
committerpixel <pixel>2007-05-28 06:52:21 +0000
commit53fdb9bc72aab1bd41126be806cf58cc73e2a625 (patch)
tree4fad84ad97bebdbe6ce3f06fe184ecb113afeba0
parent47810e5679145af5d9b43047dafdff453e09683a (diff)
Adding split function.
-rw-r--r--lib/supportlib.lua24
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