aboutsummaryrefslogtreecommitdiff
path: root/builtin/common
diff options
context:
space:
mode:
authorRyan Newell <thekingdoof@gmail.com>2014-10-08 17:11:44 -0500
committerShadowNinja <shadowninja@minetest.net>2014-11-08 12:49:50 -0500
commit90b6de173ed1321e721599fcfd322b4ba616427f (patch)
tree6871a4878b9d9c720c13bd74fe914ce036a72305 /builtin/common
parentc40e993ce4a13321e57856fb40566fa93a5ef187 (diff)
downloadminetest-90b6de173ed1321e721599fcfd322b4ba616427f.tar.gz
minetest-90b6de173ed1321e721599fcfd322b4ba616427f.tar.bz2
minetest-90b6de173ed1321e721599fcfd322b4ba616427f.zip
Add last_login field to auth.txt
Also shortens some related code and adds more parameters to string.split.
Diffstat (limited to 'builtin/common')
-rw-r--r--builtin/common/misc_helpers.lua28
1 files changed, 24 insertions, 4 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua
index 2e2eac925..ce58b3f9b 100644
--- a/builtin/common/misc_helpers.lua
+++ b/builtin/common/misc_helpers.lua
@@ -155,13 +155,33 @@ function dump(o, indent, nested, level)
end
--------------------------------------------------------------------------------
-function string:split(sep)
- local sep, fields = sep or ",", {}
- local pattern = string.format("([^%s]+)", sep)
- self:gsub(pattern, function(c) fields[#fields+1] = c end)
+function string.split(str, delim, include_empty, max_splits)
+ delim = delim or ","
+ max_splits = max_splits or 0
+ local fields = {}
+ local num_splits = 0
+ local last_pos = 0
+ for part, pos in str:gmatch("(.-)[" .. delim .. "]()") do
+ last_pos = pos
+ if include_empty or part ~= "" then
+ num_splits = num_splits + 1
+ fields[num_splits] = part
+ if max_splits > 0 and num_splits + 1 >= max_splits then
+ break
+ end
+ end
+ end
+ -- Handle the last field
+ if max_splits <= 0 or num_splits <= max_splits then
+ local last_part = str:sub(last_pos)
+ if include_empty or last_part ~= "" then
+ fields[num_splits + 1] = last_part
+ end
+ end
return fields
end
+
--------------------------------------------------------------------------------
function file_exists(filename)
local f = io.open(filename, "r")