Allow dumping userdata (#7012)
authoryou <ovvv@web.de>
Thu, 8 Feb 2018 18:17:06 +0000 (19:17 +0100)
committerSmallJoker <mk939@ymail.com>
Sun, 3 Jun 2018 15:32:00 +0000 (17:32 +0200)
builtin/common/misc_helpers.lua

index 0686c18da2b16e19e0d9ae1effb3c6e5fa7af61b..ab2da14ea64716d60b9b815a964872a8fd07cdfc 100644 (file)
@@ -120,7 +120,12 @@ end
 -- The dumped and level arguments are internal-only.
 
 function dump(o, indent, nested, level)
-       if type(o) ~= "table" then
+       local t = type(o)
+       if not level and t == "userdata" then
+               -- when userdata (e.g. player) is passed directly, print its metatable:
+               return "userdata metatable: " .. dump(getmetatable(o))
+       end
+       if t ~= "table" then
                return basic_dump(o)
        end
        -- Contains table -> true/nil of currently nested tables