aboutsummaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
authorTim <t4im@users.noreply.github.com>2016-07-07 23:58:52 +0200
committerparamat <mat.gregory@virginmedia.com>2016-07-26 04:15:06 +0100
commit58eb5f39d4e57fd9c7409efade54b5792dfefab3 (patch)
tree186d6164a7179d6815bfe0e92fc75897372655b9 /builtin/game
parentf833159a68f2ff605224ed7a5ac956e5a0ca42d8 (diff)
downloadminetest-58eb5f39d4e57fd9c7409efade54b5792dfefab3.tar.gz
minetest-58eb5f39d4e57fd9c7409efade54b5792dfefab3.tar.bz2
minetest-58eb5f39d4e57fd9c7409efade54b5792dfefab3.zip
Builtin: Fix check for a player object in core.check_player_privs
core.check_player_privs accepts as first argument a name or player object, but just tested for a string. This caused crashes inside builtin, when being passed any unexpected types. This provides a better (duck-typing like) test, better error reporting.
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/misc.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua
index 918315656..4773e0012 100644
--- a/builtin/game/misc.lua
+++ b/builtin/game/misc.lua
@@ -48,11 +48,13 @@ function core.after(after, func, ...)
}
end
-function core.check_player_privs(player_or_name, ...)
- local name = player_or_name
- -- Check if we have been provided with a Player object.
- if type(name) ~= "string" then
+function core.check_player_privs(name, ...)
+ local arg_type = type(name)
+ if (arg_type == "userdata" or arg_type == "table") and
+ name.get_player_name then -- If it quacks like a Player...
name = name:get_player_name()
+ elseif arg_type ~= "string" then
+ error("Invalid core.check_player_privs argument type: " .. arg_type, 2)
end
local requested_privs = {...}