summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/dat/clua
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-29 05:04:47 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-29 05:04:47 +0000
commit04b6d88224536e1b577c7baf29e6c8e70cf19cac (patch)
tree37556acd4ad5dc87c841748c8adf38e117d6e061 /crawl-ref/source/dat/clua
parent42fdd5f87bf73d11adfe8867514fe1e0d768ddd3 (diff)
downloadcrawl-ref-04b6d88224536e1b577c7baf29e6c8e70cf19cac.tar.gz
crawl-ref-04b6d88224536e1b577c7baf29e6c8e70cf19cac.zip
Make table_to_string() more robust, so it won't raise an error if it encounters
anything weird. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8844 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/dat/clua')
-rw-r--r--crawl-ref/source/dat/clua/util.lua27
1 files changed, 21 insertions, 6 deletions
diff --git a/crawl-ref/source/dat/clua/util.lua b/crawl-ref/source/dat/clua/util.lua
index ceff124f91..0a606d6237 100644
--- a/crawl-ref/source/dat/clua/util.lua
+++ b/crawl-ref/source/dat/clua/util.lua
@@ -258,23 +258,38 @@ function table_to_string(table, depth)
local indent = string.rep(" ", depth * 4)
+ if type(table) ~= "table" then
+ return indent .. "['" .. type(table) .. "', not a table]"
+ end
+
local str = ""
local meta = getmetatable(table)
if meta and meta.CLASS then
- str = str .. indent .. "CLASS: " .. meta.CLASS .. "\n"
+ str = str .. indent .. "CLASS: "
+ if type (meta.CLASS) == "string" then
+ str = str .. meta.CLASS .. "\n"
+ else
+ str = str .. "[type " .. type(meta.CLASS) .. "]\n"
+ end
end
for key, value in pairs(table) do
- str = str .. indent .. key .. ": "
+ local typ = type(key)
+ if typ == "string" or typ == "number" then
+ str = str .. indent .. key .. ": "
+ else
+ str = str .. indent .. "[type " .. typ .. "]: "
+ end
- if type(value) == "table" then
+ typ = type(value)
+ if typ == "table" then
str = str .. "\n" .. table_to_string(value, depth + 1)
- elseif type(value) == "function" then
- str = str .. "function"
- else
+ elseif typ == "number" or typ == "string" or typ == "boolen" then
str = str .. value
+ else
+ str = str .. "[type " .. typ .. "]"
end
str = str .. "\n"
end