aboutsummaryrefslogtreecommitdiff
path: root/builtin/common
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-06-07 08:09:06 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-06-07 09:09:06 +0200
commitc91a8c7061c83a33cca929859ea811afb985ac0a (patch)
tree28d90cc8f57d35eedb2d25ffd6456ffddb80adf1 /builtin/common
parent6c558744179b52607d552d28bf6cc6a4e49a2a14 (diff)
downloadminetest-c91a8c7061c83a33cca929859ea811afb985ac0a.tar.gz
minetest-c91a8c7061c83a33cca929859ea811afb985ac0a.tar.bz2
minetest-c91a8c7061c83a33cca929859ea811afb985ac0a.zip
[CSM] Add function to get player privileges (#5933)
* [CSM] Add function to get player privileges + move related help functions to common * Added @Zeno- const
Diffstat (limited to 'builtin/common')
-rw-r--r--builtin/common/misc_helpers.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua
index 68481f7c8..d162bc0a2 100644
--- a/builtin/common/misc_helpers.lua
+++ b/builtin/common/misc_helpers.lua
@@ -723,3 +723,28 @@ function core.pointed_thing_to_face_pos(placer, pointed_thing)
end
return fine_pos
end
+
+function core.string_to_privs(str, delim)
+ assert(type(str) == "string")
+ delim = delim or ','
+ local privs = {}
+ for _, priv in pairs(string.split(str, delim)) do
+ privs[priv:trim()] = true
+ end
+ return privs
+end
+
+function core.privs_to_string(privs, delim)
+ assert(type(privs) == "table")
+ delim = delim or ','
+ local list = {}
+ for priv, bool in pairs(privs) do
+ if bool then
+ list[#list + 1] = priv
+ end
+ end
+ return table.concat(list, delim)
+end
+
+assert(core.string_to_privs("a,b").b == true)
+assert(core.privs_to_string({a=true,b=true}) == "a,b")