aboutsummaryrefslogtreecommitdiff
path: root/builtin/common/misc_helpers.lua
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2015-07-18 14:31:34 +0200
committerest31 <MTest31@outlook.com>2015-07-21 16:58:22 +0200
commit899491325938d0b1e5bf701d33d24bb4283affaa (patch)
tree4e75c4a81854556223ccaef8ad02936fd55e82b9 /builtin/common/misc_helpers.lua
parentfa7fe510d9b77c0a7802604a5697de4e52cddba3 (diff)
downloadminetest-899491325938d0b1e5bf701d33d24bb4283affaa.tar.gz
minetest-899491325938d0b1e5bf701d33d24bb4283affaa.tar.bz2
minetest-899491325938d0b1e5bf701d33d24bb4283affaa.zip
Allow random menu images for subgames
Diffstat (limited to 'builtin/common/misc_helpers.lua')
-rw-r--r--builtin/common/misc_helpers.lua16
1 files changed, 15 insertions, 1 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua
index 1c9f2a48f..bf672e6da 100644
--- a/builtin/common/misc_helpers.lua
+++ b/builtin/common/misc_helpers.lua
@@ -159,6 +159,7 @@ function dump(o, indent, nested, level)
return "{"..table.concat(t, ", ").."}"
end
+--------------------------------------------------------------------------------
function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
delim = delim or ","
max_splits = max_splits or -1
@@ -184,9 +185,22 @@ function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
end
--------------------------------------------------------------------------------
+function table.indexof(list, val)
+ for i = 1, #list do
+ if list[i] == val then
+ return i
+ end
+ end
+ return -1
+end
+
+assert(table.indexof({"foo", "bar"}, "foo") == 1)
+assert(table.indexof({"foo", "bar"}, "baz") == -1)
+
+--------------------------------------------------------------------------------
function file_exists(filename)
local f = io.open(filename, "r")
- if f==nil then
+ if f == nil then
return false
else
f:close()